我用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。
请指导我锁定机构应该去哪里,或者应重新设计如何使用隔离的流程。