Java Quartz scheduled Job – disallow concurrent execution of Job
Just use the @DisallowConcurrentExecution Annotation on top of the Job class. See this official example or this tutorial about concurrent job execution.
Just use the @DisallowConcurrentExecution Annotation on top of the Job class. See this official example or this tutorial about concurrent job execution.
scheduler.getCurrentlyExecutingJobs() should work in most case. But remember not to use it in Job class, for it use ExecutingJobsManager(a JobListener) to put the running job to a HashMap, which run before the job class, so use this method to check job is running will definitely return true. One simple approach is to check that fire … Read more
Yes, I would store the list in the ServletContext as an application-scoped attribute. Pulling the data from a database instead is probably less efficient, since you’re only updating the list every hour. Creating a ServletContextListener might be necessary in order to give the Quartz task a reference to the ServletContext object. The ServletContext can only … Read more
Contents Eclipse project With Maven XML-Less Eclipse project If you are using a typical project in eclipse, the most basic example has a structure similar to: C:. | +—src | | log4j.dtd | | log4j.xml | | quartz.properties | | quartz_data.xml | | | \—org | \—paulvargas | \—test | \—quartz | TestJob.java | \—WebContent … Read more
You can find an answer here. I can suggest using org.reflections You can take a look at it here Reflections reflections = new Reflections(“com.mycompany”); Set<Class<? extends MyInterface>> classes = reflections.getSubTypesOf(MyInterface.class);
I would recommend an implementation like this one to recover the job after a fail: final JobDataMap jobDataMap = jobCtx.getJobDetail().getJobDataMap(); // the keys doesn’t exist on first retry final int retries = jobDataMap.containsKey(COUNT_MAP_KEY) ? jobDataMap.getIntValue(COUNT_MAP_KEY) : 0; // to stop after awhile if (retries < MAX_RETRIES) { log.warn(“Retry job ” + jobCtx.getJobDetail()); // increment the … Read more
TL;DR In Quartz 1, you may use this cron: 59 59 23 31 12 ? 2099 (last valid date). In Quartz 2, you may use this cron: 0 0 0 1 1 ? 2200 Using an expression far in the future Made some quick tests using org.quartz.CronExpression. String exp = “0 0 0 1 1 … Read more
Here’s one way… Set the auto-startup attribute on the inbound-adapter to false. Create a custom trigger that only fires once, immediately… public static class FireOnceTrigger implements Trigger { boolean done; public Date nextExecutionTime(TriggerContext triggerContext) { if (done) { return null; } done = true; return new Date(); } public void reset() { done = false; … Read more
Quartz 1 If you change your class to implement StatefulJob instead of Job, Quartz will take care of this for you. From the StatefulJob javadoc: stateful jobs are not allowed to execute concurrently, which means new triggers that occur before the completion of the execute(xx) method will be delayed. StatefulJob extends Job and does not … Read more
In spring boot, you can use an application property directly! For example: @Scheduled(fixedDelayString = “${my.property.fixed.delay.seconds}000″) private void process() { // your impl here } Note that you can also have a default value in case the property isn’t defined, eg to have a default of “60” (seconds): @Scheduled(fixedDelayString = “${my.property.fixed.delay.seconds:60}000”) Other things I discovered: the … Read more