Search code examples
javalockinghazelcast

Wait for releasing acquired locks by current HazelcastInstance when shutdown() is called


Hello fellow developers,

I have serializeable object that is stored across two Hazelcast members.

Object contains some info that can be changed on only one of the Hazelcast member at the same time.

For this purpose I am using ILock.

Everything is working fine until, Hazelcast member that acquired and holds lock for object decides to leave.

I want current Hazelcast member to wait for release its acquired and held locks before shutdown, so it can finish editing object.


Solution

  • As we discussed in comments (with @mdogan), there's no built-in mechanism for that.

    To achieve what I wanted, I have to:

    1. Store of all acquired lock keys by current Hazelcast member in ConcurrentSkipListSet<String>.
    2. Before shutdown, loop through ConcurrentSkipListSet<String> check if ILock.isLocked(), if true then wait for release.
    3. Shutdown current Hazelcast member.