Chaining job execution in Quartz

Quartz javaThere isn’t explicit way to chain jobs in Quartz. However this is still possible, by doing some tricks. Here is an explanation on how to do that (in very few words).

There are two ways to put job in chain:
– first one, by using Listeners( for example JobChainingJobListener),
– and the second one, by using JobDataMap which every job contains.
I prefer the second way with JobDataMaps. Why ? Because DataMaps are persistent so information about chained jobs survives restart of the server.

Chain is nothing more than normal queue of the jobs, so to put two jobs into chain we need to create queue from them. Queue should be bidirectional to allow easy manipulation. The idea is to put 4 properties into JobDataMaps:
– nextJobName, nextJobGroup – identify next job in chain
– previousJobName, previousJobGroup – identify previous job in chain

Those 4 variables are enough to implement standard bi-directional queue operations like: addJobToQueue(..), removeFromQueue(..), moveUp(..) and moveDown(..). One thing to remeber: adding job to chain should stop it, to avoid triggering jobs in unspecified order.

Last thing to do is to create own implementation of the Quartz Job interface which, in execute() method, will fire/trigger next job in chain, if there is any.

That’s all.

You May Also Like

Wicket form submit not safe for redirecting to intercept page

The problem When you have a form, that anybody can see, but only logged on users can POST, you may want to redirect the user to the login page, and back to the form after login Using wicket 1.3/1.4, if you do that using redirectToInterceptPage(loginP...The problem When you have a form, that anybody can see, but only logged on users can POST, you may want to redirect the user to the login page, and back to the form after login Using wicket 1.3/1.4, if you do that using redirectToInterceptPage(loginP...

GWT Hosted mode on 64bit linux

GWT for linux is build against 32bit architecture. It contains some SWT/GTK 32bit modules. So if you try to run it with 64bit java it failsException in thread "main" java.lang.UnsatisfiedLinkError: /opt/tools/sdk/gwt/gwt-linux-1.5.3/libswt-pi-gtk-3235....