Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled execution (cron) should never execute ahead of exact scheduled time [SPR-12099] #16715

Closed
spring-issuemaster opened this issue Aug 19, 2014 · 2 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Aug 19, 2014

Beau Grantham opened SPR-12099 and commented

Scheduled executions (using cron) occasionally execute ahead of the scheduled execution time. The is particularly a problem when the code depends some aspect of the date/time and the value is incorrect.

See the simplified example below along with log4j output. I would have expected the execution to be no earlier that 2014-08-19 00:00:00.

@Scheduled(cron = "0 0 0 * * *")
public void dailyReports() {
     Date today = new Date();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
          logger.info("Executing job for " + sdf.format(today));
          // [...]
          return;
}
2014-08-18 23:59:59,801 [pool-7-thread-25] INFO [...] Executing job for 2014-08-18

Affects: 4.0.5

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Aug 19, 2014

Juergen Hoeller commented

It seems that we're correctly calculating the next execution time there... and that the target executor (e.g. the JDK's ScheduledThreadPoolExecutor) isn't 100% accurate in its actual execution points.

If you're relying on the execution being on the new day, the best I can recommend for the time being is to add a second or two to your cron trigger...

Juergen

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 12, 2019

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.