Lock.tryLock with lease time #1564

gurbuzali opened this Issue Jan 15, 2014 · 12 comments


None yet

Hazelcast has lock with lease time feature but does not support tryLock with lease time

@sancar sancar was assigned by enesakar Feb 28, 2014
pmanvi commented May 14, 2014


@sancar sancar removed their assignment Jun 4, 2014




@ajermakovics ajermakovics added Team: Core and removed Team: Core labels Oct 14, 2014

Is tryLock with lease time now supported? I see this was closed, but don't see that it was resolved.


this is an open issue, we've not yet solved it.
the closed one was only a duplicate. Please see #3692


is this so hard to implement? I mean... one year and counting.... looks like copy/paste to me from the normal "lock" feature.


Hey @logemann, yeah I guess you're kinda right.
Would you like to give it a try and going to implement it? We would appreciate your help.

mattk42 commented Jun 3, 2015

I have taken a stab at this and it seems to be working. Going to spend some time on unit tests and should have a pull request soon.



@gurbuzali gurbuzali modified the milestone: 3.6, Backlog Jun 21, 2015

fixed via #5658

@gurbuzali gurbuzali closed this Jul 14, 2015

can I use this combination as workaround to specify lease time?

if (lock.tryLock(1, TimeUnit.SECONDS) {
   lock.lock(2, TimeUnit.SECONDS);

no need for a workaround for 3.6, we've implemented tryLock with lease time.
please take a look at https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/core/ILock.java#L90

for the previous versions, yes it works but you need to unlock twice since you've locked it twice:
one with tryLock and one with lock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment