Quartz scheduler during server restart - java

I am trying to implement a quartz scheduler which should run every n days.
Say I wrote a trigger which runs every 10 days. If I restart my server on 9th day, the cron jobs will be reloaded based on current time. So it won't fire on the 10th day instead it will fire on 19th day.
Is there any way we to trigger jobs based on last run date so that it will trigger on 10th day.

If you "just" have to remember your job executions, you have to persist it in some way. An approach with minimum impact would be using something like a Quartz JDBCJobStore.
Maybe you are already using Spring and in case you need a more "sophisticated" (single steps, start & stop & restart) way take a look at Spring Batch.

Related

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
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

Getting Started With Real Time Event Scheduling in Java on Linux?

I'm working on a project that will record data on real time events using Java on a linux system.
I have all of the HTML scraping stuff down, that's fine, what I need to figure out is the scheduling and management of the tasks.
There are potentially up to forty events occurring each week, at varying times and events can last up to three hours.
I can create and update the calendar of these events at will, my problem is how to:
Schedule a process to scrape each event at the right time, and update the schedule if there's a change.
Ensure once the scrape process has begun that it stays running for the entire (indeterminate) duration of the event.
Can anyone advise how best to approach this? I'm not sure where I need to start.
Thanks!
a) Schedule a process to scrape each event at the right time, and
update the schedule if there's a change.
If you do not want to use a library, a good starting point for scheduling your tasks can be ScheduledExecutorService. Though you may find other scheduling frameworks useful for your problem out of which Quartz can specifically give you a flexibility in how to schedule the next task based on the current schedule execution results; it also provides a cron capability so that if your schedule is fixed, you can take advantage of a fixed scheduled calendar.
b) Ensure once the scrape process has begun that it stays running for
the entire (indeterminate) duration of the event.
Assuming that you're using a library for HTML scraping, you don't need to ensure it's running since it will be Java task object initiated from your application.

How to schedule multiple jobs in quartz scheduler using same trigger?

I am using quartz scheduler in my spring project. I have to run a job after another job which is scheduled to run in every 15 mins? I cant run this job concurrently as both of this jobs have to access same mail account using different protocols(one to send:smtp and other to receive: imap) and it may cause problems. Please reply quickly, as its an urgent requirement.
Just write a wrapper job class that launches second job after the first. You could then reuse separate jobs in the future if there will be any necessity.
You could do something with writing a job listener to recognize when the first job ends, and have it start the second. But the solution first suggested by mindas is easier - wrap both your jobs in another Job implementation, which is the one you actually schedule.

Where to get 1440 free cron jobs a day?

I'm making a program for my own use.
In this program, I need to set up cron job. The cron job should run every minute (24 hr * 60 mins = 1440 times). Thus, I'll need to set up a cron job with a frequency of 1 minute.
I think Google App Engine gives free cron job. But I'm very new to it. I downloaded the java SDK and read the document but understood nothing :( So, I can't use Google App Engine.
Is here any other free service like Google app engine which but with easier inferface???
All I want is a cron job with 1 minute frequency
Please help/suggest me...
Thank you
Just install linux.
If this is a java app, then you can use Quartz, right? This way you can control what to do when the job fails (like cleaning up certain resources, sending emails, etc).
Maybe you want to use a service like setcronjob.com.
This lets you specify a URL that will be triggered periodically (according to the cron pattern you choose).
Of course, you still need to have a server somewhere to host the URL and implement the actual task there.
You can do this in App Engine - see the cron docs for details. In order to provide any more specific help, we'd need to know what you want that cron job to do, precisely.
I had the similar need. Ended up testing a whole bunch of scheduling services. Check out cronservice.co.uk/new/,
setcronjob.com or mywebcron.com. I ended up using the scheduler.codeeffects.com because of their set of features and the interface. Google for others, there are tons services like this. Most are free or give free stuff. Sorry for the late reply, but I thought this might help.
To schedule a job in Java, use cron.xml
Python uses the more terse cron.yaml format.
In both cases, it's actually quite easy to use, you can schedule jobs, with the following actual description and Google App Engine will understand what it means:
every 12 hours
every 5 minutes from 10:00 to 14:00
2nd,third mon,wed,thu of march 17:00
every monday 09:00
1st monday of sep,oct,nov 17:00
every day 00:00

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