Home > Software design >  How to unlock @Lock(LockModeType.PESSIMISTIC_WRITE) if there is no transaction
How to unlock @Lock(LockModeType.PESSIMISTIC_WRITE) if there is no transaction

Time:06-14

I have put @Lock(LockModeType.PESSIMISTIC_WRITE) on a query and working on it in service layer with @Transactionsal annotation. The lock is acquired successfully. But for some cases, the transaction could not be happened. And this lock takes time to be released. My concern is how can I release the lock immediately ?

CodePudding user response:

You can explicitly unlock by

entityManager.lock(entityObject, LockModeType.NONE);

  • Related