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

Me on Hadoop on Parleys

Finally I've managed to import my WarJUG presentation to parleys.com. See for yourself :) If you've got problems with opening the parleys' version try the ones uploaded to youtube. Here is part 1: And here is part 2: Finally I've managed to import my WarJUG presentation to parleys.com. See for yourself :) If you've got problems with opening the parleys' version try the ones uploaded to youtube. Here is part 1: And here is part 2:

Sonar Gerrit Plugin Release

I am happy to announce a first release of my Sonar Gerrit plugin. This plugin reports Sonar violations on your patchsets to your Gerrit server. Sonar analyses full project, but only files included in patchset are commented on Gerrit. Please forward to project page for installation instructions. This plugin is intended to use with Gerrit Trigger plugin for Jenkins CI server. Together they provide a great tool for automatic static code analysis.I am happy to announce a first release of my Sonar Gerrit plugin. This plugin reports Sonar violations on your patchsets to your Gerrit server. Sonar analyses full project, but only files included in patchset are commented on Gerrit. Please forward to project page for installation instructions. This plugin is intended to use with Gerrit Trigger plugin for Jenkins CI server. Together they provide a great tool for automatic static code analysis.