![](/img/trans.png)
[英]How to create a scheduler task in Window Task Scheduler using Java?
[英]Rows getting locked while updating the table using Task scheduler in Java
我已經用Java編寫了一個Task Scheduler,它每1分鍾調用一次該方法。 現在,此應用程序已部署到正在運行2個實例的SIT服務器中。 現在,讓我告訴您我構建的方案。
<task:scheduled-tasks scheduler="myScheduler">
<task:scheduled ref="myBean" method="takeLunch" fixed-delay="60000" />
</task:scheduled-tasks>
<task:scheduler id="myScheduler"/>
流是
1. Get the employees who are ready to take the lunch. This is the eligiblity condition.
SELECT EMP_ID FROM EMPLOYEES WHERE WORK_STATUS='COMPLETED'
(因為兩個實例都嘗試同時觸發查詢,所以這里可能會有死鎖嗎?)
2. I've another table called "LUNCH_STATUS" where I will keep track of their lunch.
INSERT INTO LUNCH_STATUS(EMP_ID,STATUS) .....
在這里將插入所有員工ID,其狀態為空。
3. I will get the first employee from the LUNCH_STATUS whose status is empty and I will update in the same table as the status "LUNCH IN PROGRESS"
4. While taking lunch, I've some business logic, once the lunch is done, I will update the status as "COMPLETED"
UPDATE LUNCH_STATUS SET STATUS='COMPLETED' WHERE EMP_ID = ?
5. Once this update is done, I should update the main table EMPLOYEES
UPDATE EMPLOYEES SET WORK_STATUS='WORK RESUMED' WHERE EMP_ID=?
當我在本地計算機上運行時,這種方法工作正常,但有時在SIT服務器中卻不能。
現在,這里的問題有時是當多個員工都有資格吃午餐時,即使已完成午餐,應用程序也不會更新狀態為“午餐已完成”。 記錄被鎖定的某個位置。 有什么想法我應該考慮哪些步驟?
我對所有這些DAO方法(INSERT,SELECT和UPDATE)使用@Transactional批注和隔離屬性SERIALIZABLE。
請指導我在哪里使用鎖定機制,否則應重新設計有關如何使用隔離的流程。
您必須實現集群環境的石英調度程序。 例如在帶有數據庫的GitHub中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.