3

I'm encountering a very strange problem in my server when executing 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 method run() inside ReportingJob() is only printing.

You can see my schedule is supposed to run every 10 minutes.

I'm running this on tomcat. On my localhost, everything is all good. But in my server (Ubuntu 16.4) every time the job executes, execute earlier. I don't know why.

Some of my logs in 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 already checked the server.xml config and it's the same.

drupal2me
  • 69
  • 4
  • What java version are you using? – SpaceTrucker Jun 12 '17 at 16:54
  • version "1.8.0_131" – drupal2me Jun 12 '17 at 16:57
  • Check if you have a stable NTP server on your production server. – Alex Roig Jun 12 '17 at 17:04
  • `Local time: Mon 2017-06-12 17:10:09 UTC Universal time: Mon 2017-06-12 17:10:09 UTC RTC time: Mon 2017-06-19 00:17:55 Time zone: Etc/UTC (UTC, +0000) Network time on: yes NTP synchronized: yes RTC in local TZ: no` – drupal2me Jun 12 '17 at 17:18
  • In your first log, intervals are `09:55` then `10:00` then `-00:29`. If you edited the log before pasting it here, please re-edit in a believable way ;) If you really saw that, then it's proof that your system clock is jumping, so there is no surprise that you see varying delays. The doc for `ScheduledExecutorService` says "*expiration of a relative delay need not coincide with the current Date at which the task is enabled due to network time synchronization protocols, clock drift, or other factors.*" – Hugues M. Jun 12 '17 at 20:19

0 Answers0