How to validate Job lock_owner and rev in Java Delegate?

Hello Team,

Some how Camunda pickup a same job and we end up with Duplicate processing? We have lock duration as 20 min, and execution is way faster that that.

[2022-06-23 22:23:43,226]- org.camunda.commons.logging.BaseLogger.logDebug:Line 118 - ENGINE-03009 SQL operation: ‘UPDATE’; Entity: ‘AcquirableJobEntity[id=fc42fd85-f329-11ec-bfa2-00224843204f]’

JobExecutor : [2022-06-23 22:23:43,226]- org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug:Line 143 - ==> Parameters: 2(Integer), 2022-06-23 19:43:43.218(Timestamp), 7e8f9b0c-c695-49a4-822e-b7e49fe467b7(String), 2022-06-23 19:23:39.31(Timestamp), fc362c2f-f329-11ec-bfa2-00224843204f(String), true(Boolean), fc42fd85-f329-11ec-bfa2-00224843204f(String), 1(Integer)



[2022-06-23 22:24:02,495]- org.camunda.commons.logging.BaseLogger.logDebug:Line 118 - ENGINE-03009 SQL operation: ‘UPDATE’; Entity: ‘AcquirableJobEntity[id=fc42fd85-f329-11ec-bfa2-00224843204f]’

JobExecutor: [2022-06-23 22:24:02,497]- org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug:Line 143 - ==> Parameters: 5(Integer), 2022-06-23 19:44:02.483(Timestamp), 7e8f9b0c-c695-49a4-822e-b7e49fe467b7(String), 2022-06-23 19:23:39.31(Timestamp), fc362c2f-f329-11ec-bfa2-00224843204f(String), true(Boolean), fc42fd85-f329-11ec-bfa2-00224843204f(String), 4(Integer)

And when first pickup job completed at end of opeartion it failed with exception:

org.camunda.commons.logging.BaseLogger.logDebug:Line 118 - ENGINE-16002 Exception while closing command context: ENGINE-03005 Execution of 'DELETE MessageEntity[fc42fd85-f329-11ec-bfa2-00224843204f]' failed. Entity was updated by another transaction concurrently.
org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'DELETE MessageEntity[fc42fd85-f329-11ec-bfa2-00224843204f]' failed. Entity was updated by another transaction concurrently.
	at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.concurrentUpdateDbEntityException(EnginePersistenceLogger.java:135) ~[camunda-engine-7.13.0.jar!/:7.13.0]
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.handleConcurrentModification(DbEntityManager.java:411) ~[camunda-engine-7.13.0.jar!/:7.13.0]
	at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:352) ~[camunda-engine-7.13.0.jar!/:7.13.0]

So, thinking that if we can validate at JavaDelegate, and at first line of execute can check lock_owner and rev it’s executing is same as in current DB; we can avoid such problem.

Could anyone do needful, please?