Lock.tryLock with lease time #1564

Closed
gurbuzali opened this Issue Jan 15, 2014 · 12 comments

Projects

None yet
@gurbuzali
Member

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
pmanvi commented May 14, 2014

+1

@sancar sancar removed their assignment Jun 4, 2014
@drewstewart

+1

@logemann

+1

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

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

@gurbuzali
Member

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

@logemann

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

@noctarius
Member

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
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.

@palevi67

+1

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

fixed via #5658

@gurbuzali gurbuzali closed this Jul 14, 2015
@nick7ikin

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

if (lock.tryLock(1, TimeUnit.SECONDS) {
   lock.lock(2, TimeUnit.SECONDS);
   ....
   lock.unlock();
}
@gurbuzali
Member

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