1

is there a way to pass a BlockingQueue to a job in the Quartz framework? I tried to use the JobDataMap for passing the BlockingQueue but that doesn't seem to work. Here the relevant code fragment:

JobDetail job = newJob(Jobby.class)
  .withIdentity("myJob", "group1")
  .usingJobData("buffer", queue)
  .build();

Perhaps someone has an idea on how to achieve this.

Jonas
  • 121,568
  • 97
  • 310
  • 388
evermean
  • 1,255
  • 21
  • 49
  • What do you want to achieve? What is your use case? Quartz accepts any serializable object. – Tomasz Nurkiewicz Jun 04 '12 at 16:22
  • I have a few jobs that should write their data in the BlockingQueue in a Producer/Consumer kind of manner. So for every job to have access to the BlockingQueue I have to somehow pass it to the job...thats why I thought I'll simply use the JobDataMap for that purpose. – evermean Jun 05 '12 at 07:55

1 Answers1

1

Looks like you are trying to implement producer/consumer design pattern where producers are placing work in a queue and consumer checks that queue periodically using Quartz. This design isn't bad, however your implementation won't work. By passing that queue to the job data Quartz will serialize it and deserialize it back when jobs trigger. The queue won't be passed by reference but by value (copy). This is understandable if you realize that Quartz should work in a distributed environment, where job is scheduled and persisted to the database on one node and deserialized and executed on other node.

That being said you need to reevaluate your implementation. If you don't care about clustering and distribution, make your queue somehow globally available. Your options are:

  • global - please, no
  • resource available via
  • bean injected to both producers and job class (Spring supports Quartz quite well)
  • ...

I specifically recommend using , is also a nice option. But if we are talking about - why not consider using some lightweight implementation instead of Quartz? You would avoid latency.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • @evermean: can you reveal which approach have you taken? – Tomasz Nurkiewicz Jun 07 '12 at 06:28
  • @TomaszNurkiewicz Could you explain how this would be implemented using spring? Just inject a BlockingQueue to Job A and Job B? I have a similar question here: http://stackoverflow.com/questions/11922827/how-do-i-notify-a-consumer-job-that-producer-job-is-done/11923589#11923589 – geffchang Aug 13 '12 at 01:23
  • @TomaszNurkiewicz : Why do you discourage global singletons? Isn't a spring bean a similar kind of thing – nikel Sep 27 '16 at 10:57