1

I am using quartz + spring for scheduling. If I want to store some static data in memory and use it for every iteration of the job, how can that be possible.

Thanks

gnreddy
  • 2,393
  • 4
  • 22
  • 18
  • Is it a desktop application or a web application ? – Apurv Feb 27 '13 at 07:19
  • its a web application. – gnreddy Feb 27 '13 at 07:26
  • You can use the Servlet Context. Check this for details about servlet context -> http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html and this for its usage -> http://stackoverflow.com/questions/3215988/how-to-get-and-set-a-global-object-in-java-servlet-context – Apurv Feb 27 '13 at 07:29

1 Answers1

0

I will assume that you are using Quartz 1.8. Quartz 2.x offers annotations that make the implementation a bit more convenient but once you have the code for 1.8, it is not hard to replace it with those annotations.

  1. Make sure your job implements the StateFulJob interface. If you use Quartz 2.x, implement the Job interface instead and annotate your class with @PersistJobDataAfterExecution.
  2. From the job context, retrieve the JobDataMap with context.getJobDetail().getJobDataMap().
  3. Now you can get and put values into that map and each value that you put into the map will be available to subsequent runs of the job.

Make sure that all objects you put into the JobDataMap are serializable. Also configure Quartz not to run the job concurrently to prevent a race condition.

Fabian Ritzmann
  • 1,345
  • 9
  • 20