0

Using Spring/Quartz, I have an ProducerJob that is run first. Then I have a ConsumerJob that must wait for the result of ProducerJob (which creates records in the DB).

What's the best way for ConsumerJob to be notified of the results of ProducerJob? Should I let ConsumerJob to constantly check the database, and sleep/wait if ProducerJob is not yet done?

I realize my question may be similar to Pass BlockingQueue in JobDataMap of Quartz, although no specific implementation was identified. Still not getting how this would be implemented though.

Community
  • 1
  • 1
geffchang
  • 3,279
  • 2
  • 32
  • 58

1 Answers1

2

In the Producer/Consumer pattern the consumer has to wait for the data the producer prduces. If you want to decouple both using a database, the consumer has to poll. Yes. Another solution is to use a BlockingQueue and let the consumer write the database entries. This would reduce database load and is propably simpler to implement. And the producer is mutch faster, which is often a reason to use this pattern.

Bernd Ebertz
  • 1,317
  • 8
  • 10
  • Edited my question. It should have been "ConsumerJob to be notified of the results of ProducerJob", not the other way around. I get the idea, but have no idea this would be done with Quartz, when a job is scheduled. – geffchang Aug 13 '12 at 01:18
  • In fact there are three option to implement thelike: – Bernd Ebertz Aug 14 '12 at 08:35
  • Could you please explain what the 3 options are? – geffchang Aug 14 '12 at 08:46
  • BockingQueue if producer and consumer run within the same vm, just different threads. If the consumer run with an EJB server JMS with MessageDriven Beans is the default. (This can be used outside EJB, too, but MessageDriven beans are really nice for it) If one has the need for different processes and don't want to rely on a JMS implementation polling the database is the method of choice. Or sometimes even with files... Unfortunately I don't have a isulated example for either of them. – Bernd Ebertz Aug 14 '12 at 08:47