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()機制,如果我可以阻止工作線程讀取隊列中正在寫入的內容。
任何想法爲更好的方法。
感謝,