Search code examples
javaredislockingredisson

Redisson release lock from different threads


I'm trying to create an infrastructure where different machines acquire shared locks through Redisson. Once the lock is acquired, some async tasks gets done, finally, when I finish the job, I'm releasing the Redisson lock through the thread currently running - but i receive the following error

java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: xxxxx thread-id: 57

So, I understand the meaning of that, but since I want to perform asynchronous work, I cannot use the acquiring thread to perform the release.

Should I not use Redisson locks? What is the best match for async work like that?


Solution

  • As zapl mentioned, Java documentation shows that this is the proper behavior of a java lock. After discussing the issue on Reddison's GitHub page, it seems like Redisson Lock was not designed for that, and that the Redisson Semaphore will support async operations soon.

    At the meantime, i plan to allocate a single thread to perform ALL locking and unlocking. Since Redisson has the support for async, non-blocking calls, this solution seems reasonable for now.