How do I notify a Consumer job that Producer job is done?

六月ゝ 毕业季﹏ 提交于 2019-12-13 04:17:20

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/11922827/how-do-i-notify-a-consumer-job-that-producer-job-is-done

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!