0
我正在建立一个系统,它有一个基本的产品消费者的范例味道,但生产者部分需要在交易模式。 这是我确切的情况:BlockingQueue内部交易java
Poller Thread -
[Transaction START]
Polls the DB for say 10 records
* Sets the status in DB for those records as IN-Progress
* Puts the above 10 records in a LinkedBlockingQueue - workqueue
[Transaction END]
Worker Thread Pool of 5
* Polls the workqueue for the tasks, do some lookups and update the same records in DB with some looked up values.
现在我的问题是1的过程的一部分,因为如果让说,一些原因,我的提取和更新由DB是成功的,但在队列中插入的过程,一个失败记录,我可以回滚整个事务,并且我的数据库中的所有记录都将处于NOT Processed状态,但可以在此工作队列中插入一些元素,并且我的工作线程池可以拾取它们并开始处理,而不应该发生。
试图找到是否有办法以跨国的方式写入到blockingqueue。
考虑添加一些writelock()readlock()机制,如果我可以阻止工作线程读取队列中正在写入的内容。
任何想法为更好的方法。
感谢,