RMagen
RMagen

Reputation: 622

spring scheduler after maintenance

we are using spring sceduler using

@Scheduled(cron = "0 15 10 15 * ?")

the problem is that some time we have maintenece and the system is down when the job is sceduled to run. is there another sceduler we can use ? maybe a parameter that checks if there was scedualed job that didnt run during maintenence and run it when the system is up? or a recomenation for a different scedualer to use Thanks

Upvotes: 0

Views: 122

Answers (1)

Michael Gantman
Michael Gantman

Reputation: 7808

M. Deinum mentioned Quartz as a possible solution. It is a very advanced scheduling product that may handle scheduling for multiple nodes insuring that the job would run only on one node. It has many other features. I haven't used it in long while so you can look up if it is something you want to use.

However, I have dealt with your particular case in a simpler way. Part of the scheduled job responsibility was upon each run to write down into a DB table the last scheduled time (the one in the past that triggered the current run), the next scheduled time and the actual last execution time. Then, after a down time when the server starts up it has to check if the next scheduled time is in the past (also the last execution time will be older then the next scheduled time). If it is so, it is your flag that the the job missed its running due to down time (or any other reason). So you can reschedule or run it now

P.S. This will not address your actual problem, but I wrote my own scheduler and published it as part of an open-source library. My scheduler allows you to set the time intervals in more human readable form such as "4h" for 4 hours or "30m" for 30 minutes and so forth. Also it can handle multiple tasks scheduling and allows you to specify the number of threads that will handle all your scheduled tasks. You can read about it here. The library is called MgntUtils and you can get it as Maven artifacts or from Github repository releases (with source code and Javadoc included). You can read an article about the library that describes some of the features here

Upvotes: 3

Related Questions