Regarding InterruptedException using tryLock() vs lockInterruptibly() ?

153 views
Skip to first unread message

onos....@gmail.com

unread,
Jun 30, 2016, 2:49:31 AM6/30/16
to Hazelcast
Hi!

In a thread i try to get a lock. During shutdown of the application, 
i call Thread.interrupt() to receive a InterruptedException in the thread.

Using version with lock.tryLock() the InterruptedException is catched.
With lock.lockInterruptibly() or tryLock(long var1, TimeUnit var3) i never get an InterruptedException.

How they differ ?

BTW: In the hazelcast lock test 'testLockInterruptibly' i saw the property OPERATION_CALL_TIMEOUT_MILLIS is set.
So lock.lockInterruptibly() will only throw an InterruptedException after this timeout expires ?

VERSION WORKING:
try {
    while(!lock.tryLock()) {
        Thread.sleep(300);
    }
} catch (InterruptedException e) {
    LOG.error(e.getMessage());
}

VERSION NOT WORKING:
try {
    lock.lockInterruptibly();
} catch (InterruptedException e) {
    LOG.error(e.getMessage());
}

BR
Andreas

Peter Veentjer

unread,
Jun 30, 2016, 3:27:05 AM6/30/16
to haze...@googlegroups.com
The interrupt is noticed eventually. Currently the mechanism for blocking operations is quite complex and the remote call is repeatedly retried (internal matter). When it is retried, the interrupt status is checked and if set, the request is not retried and the InterruptedException thrown.

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at https://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/98d3721c-173a-467d-a3dd-a89c9753a8f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

onos....@gmail.com

unread,
Jun 30, 2016, 7:09:17 AM6/30/16
to Hazelcast
Hi Peter

So the version with tryLock() is a way to go to get notified about an InterruptedException ?

BR
Andreas
Reply all
Reply to author
Forward
0 new messages