0

Quartz job works by trigger 0 0 19-5 * * ? (every hour from 7:00 PM to 5:00 AM). Process may take a long time, more than 1 hour. Cron expression is a part of external configuration. How to graceful stop Quartz job after 5:00 AM if process continue works?

Even if we start last iteration at 4:00 AM, there is no guarantee that it will be completed in 1 hour. Also if we start the last iteration at 3:00 AM, there is no guarantee that it will complete in 2 hours.

Valeriy
  • 1,365
  • 3
  • 18
  • 45
  • you could have a @Scheduled method that runs at 5am. It [gets all currently executing jobs](http://www.quartz-scheduler.org/api/2.3.0/org/quartz/Scheduler.html#getCurrentlyExecutingJobs--), for each job, get the job key and call the [scheduler.interrupt(JobKey)](http://www.quartz-scheduler.org/api/2.3.0/org/quartz/Scheduler.html#interrupt-org.quartz.JobKey-)? Also, if a job must end at 5, isnt it unnecessary to start a job at 5? – experiment unit 1998X Jul 13 '23 at 08:33
  • You could save the job ids and schedule a job at 5AM to stop those, which are still running. About how to gracefully stop the job, you can check [How to interrupt or stop currently running quartz job?](https://stackoverflow.com/questions/7159080/how-to-interrupt-or-stop-currently-running-quartz-job). – Chaosfire Jul 13 '23 at 08:33

0 Answers0