How to get and set a global object in Java servlet context

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

Quartz retry when failure

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

spring integration + cron + quartz in cluster?

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

How to change Spring’s @Scheduled fixedDelay at runtime?

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