我有两个不同的计划cron作业,每15分钟运行一次并在60秒内完成作业。在同一enity两种行为:看了那么进程,然后使用JpaRepository保存方法保存entitiy并导致以下错误如何避免造成ObjectOptimisticLockingFailureException的两个计划作业的冲突
org.springframework.orm.ObjectOptimisticLockingFailureException: Object of class [nl.coin.comp.domain.ServiceProvider] with identifier [105]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) : [nl.coin.comp.domain.ServiceProvider#105]
作为修复我想避免两个作业之间的冲突。我正在考虑对两者使用@Scheduled(fixedelay)不同的固定延迟,但它们也可以重叠。 请帮我这个。
再试一次?这就是您通常在乐观锁定失败时执行的操作。 – Kayaman
感谢您的答复,但我不想重试,因为我的应用程序将运行在不同的节点上,并具有相同的分贝,所以如果1节点的工作做的任务,我很好这个异常但在同一个应用程序实例我想避免两个工作之间的冲突。 – Laxmikant