ScheduledExecutorService is executed with a different delay each time

I am facing a very strange problem on my server while doing some jobs.

My code:

@WebListener
public class ReportingScheduler implements ServletContextListener {

private ScheduledExecutorService scheduler;

@Override
public void contextInitialized(ServletContextEvent event) {

    scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new ReportingJob(), 0, 10, TimeUnit.MINUTES);
}

@Override
public void contextDestroyed(ServletContextEvent event) {
    scheduler.shutdownNow();
}

      

The run () method inside ReportingJob () is print-only. In the meantime, there is no need to worry about it. ”

You can see that my schedule should run every 10 minutes.

I am running this on tomcat. Everything is fine on my localhost. But on my server (Ubuntu 16.4) every time the job is done it gets executed before. I do not know why.

Some of my logs on ubuntu server:

2017-06-12 16:15:02 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:24:57 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:34:27 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:43:58 INFO  ReportingJob:49 - START 10min JOB

      

On my localhost:

2017-06-12 16:15:02 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:25:02 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:35:02 INFO  ReportingJob:49 - START 10min JOB
2017-06-12 16:45:02 INFO  ReportingJob:49 - START 10min JOB

      

I have already checked the server.xml config and the same.

+3


source to share





All Articles