spring scheduler after maintenance - java

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

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

Related

Schedule task after certain time when another task finishes execution

I am working on spring framework based application.
I have a requirement in which when user logs in to the system, then after certain time gap say 2 minutes or 5 minutes(which should be configurable), another task will start its execution. After that execution completed, result will be published on UI.
So, can anyone tell me the way to implement this in Spring framework.
I do not know if there is a specific way to do it in Spring.
I usually exploit the JAVA SE 7 interface ScheduledExecutorService
There are a lot of samples on the web.
One of them is here.

Is there a way to specify the duration for which a task should run using Quartz library

I am looking for a way to specify the duration for a particular task to run - e.g. a particular file cleaner task may not run longer than 2 minutes. If it finishes under 2 minutes - great, but it should terminate after 2 minutes.
Does Quartz or any other library provide some effective way of doing so?
There is no such feature in quartz. You'll have to encapsulate the "timeout manager" in your job implementation.
You should detach the actual job implementation in a separate Task that is managed by the Quartz Job.
Take a look to this example: https://stackoverflow.com/a/2275596/1517816
Assume your QuartzJob is the Test class and move your business logic in the Task class.
Hope it helps

What framework to use for advanced job scheduling in Java?

In my application I need to have periodically run background tasks (which I can easily do with Quartz - i.e. schedule a given job to be run at a specific time periodically).
But I would like to have a little bit more control. In particular I need to:
have the system rerun a task that wasn't run at its scheduled time (i.e. the server was down and because of this the task was not run. In such a situation I want the 'late' task to be run ASAP)
it would be nice to easily control tasks - i.e. run a task on demand or see when a given task was last run or reschedule a given task to be run at a different time
It seems to me that the above points can be achieved with Spring Batch Admin, but I don't have much experience in this area yet. Also, I've seen numerous posts on how Spring Batch is not a scheduling tool so I'm becoming to have doubts what the right tool for the job is here.
So my question is: can the above be achieved with Spring Batch Admin? Or perhaps Quartz is enough but needs configuring to do the above? Or maybe I need both? Or something else?
Thanks a lot :)
Peter
have the system rerun a task that wasn't run at its scheduled time
This feature in Quartz is called Misfire Instructions and does exactly what you need - but is a lot more flexible. All you need is to define JDBCJobStore.
it would be nice to easily control tasks - i.e. run a task on demand or see when a given task was last run or reschedule a given task to be run at a different time
You can use Quartz JMX to access various information (like previous and next run time) or query the Quartz database tables directly. There are also free and commercial management tools basex on the above input. I believe you can also manually run jobs there.
Spring Batch can be integrated with Quartz, but not replace it.

How to do "massive" Job Scheduling (Quartz?)

I have a general question related to the quartz scheduling framework:
I need to perform a task after a fixed amount of time after a user registration. For the sake of simplicity let's say exactly 1 hour after registration of a user in my system. The job MUST be done, even if the system is restarting during this one hour the task must be remembered and it MUST be performed later if my system is down at the usual time.
Is this something where I can or where I would use Quartz? I looked at persistent jobs which looks quite promising but I am not sure if this will still work out for 1000 jobs a day. Furthermore, I am not sure about the performance implications. Maybe someone can help me with information here.
If Quartz is not the right choice, which other ways/frameworks do you see for this issue? My application is a Java 6/Spring 3 based Web-App.
Thanks for your help!
We are using quartz persisted job store successfully in our production environment for a SaaS platform application where 100s of jobs are running.

Java - Scheduling a daily task

I'm looking for an effective way to execute a method everyday at 3PM regardless of when the application was initially run or how long it has been running.
This must be done entirely from the application with no OS intervention (ex. Windows Task Scheduler)
I have been experimenting with java.util.Timer in varies configurations but I have had no success.
Any help would be appreciated.
Thanks.
You should take a look at Quartz which is a Java-based job scheduling system.
You will probably want to use something like the quartz engine it can do things like execute tasks that missed (like during a ahem crash) and it takes the work out of trying to manage threads.
For example if you use threads and put it to sleep and wake it up 86400 seconds (one day) later you will wake up and hour late (day = 82800 seconds) or early (day = 90000 seconds) on DST change over day, so be careful with whatever solution you choose
A built-in JDK way is to do what others suggested and first calculate :
currentTime - desiredTime
Then you can use something like a schedule executor to submit the tasks, and run them with a particular delay. This is far simpler than the options you have with frameworks like Quartz, but doesn't require an external dependency.
Also, you should always list which JDK you're using, so people can provide solutions for your version of the JDK.
You can start a thread that calculates the difference to the next 3pm and sleeps for that time. When it wakes up it executes the method and recalculates and sleeps. Is this what you meant?
As stated by others Quartz is a choice, with it you can do cron-like operations, jobs or triggers, here is a link on this subject: http://www.ibm.com/developerworks/java/library/j-quartz/index.html
Jcrontab
Jcrontab is a scheduler written in Java. The project objective is to provide a fully functional schedules for Java projects.

Categories

Resources