如何通知消费者工作完成生产者工作? [英] How do I notify a Consumer job that Producer job is done?
问题描述
使用Spring/Quartz,我有一个ProducerJob,它首先运行.然后,我有一个ConsumerJob,它必须等待ProducerJob(在数据库中创建记录)的结果.
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).
如何将ProducerJob的结果通知给ConsumerJob?我应该让ConsumerJob不断检查数据库,还是在ProducerJob尚未完成时进入睡眠/等待状态?
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?
我意识到我的问题可能类似于Quartz JobDataMap中的 Pass BlockingQueue ,尽管未确定具体的实现方式.仍然没有得到实现的方式.
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.
推荐答案
在生产者/消费者模式中,消费者必须等待生产者提供的数据.如果要使用数据库解耦这两种方法,则使用者必须轮询.是的.另一种解决方案是使用BlockingQueue并让使用者编写数据库条目.这将减少数据库负载,并且很容易实现.生产者的速度更快,这通常是使用此模式的原因.
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.
这篇关于如何通知消费者工作完成生产者工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!