Home » Java ReentrantLock lockInterruptibly() Method

Java ReentrantLock lockInterruptibly() Method

by Online Tutorials Library

Java ReentrantLock lockInterruptibly() Method

The lockInterruptibly() method of ReentrantLock class hold the lock until or unless the current thread is interrupted.

Syntax

Parameter

No parameter is passed.

Returns

NA

Throws

InterruptedException – if the current thread is interrupted

Example 1

Test it Now

Output:

0  Thread-0  1  Thread-0  4  5  

Example 2

Test it Now

Output:

Thread-1 is Waiting to get the lock       java.lang.ThreadGroup[name=main,maxpri=10]       java.lang.ThreadGroup[name=main,maxpri=10]       java.lang.ThreadGroup[name=main,maxpri=10]       java.lang.ThreadGroup[name=main,maxpri=10]       false       java.lang.ThreadGroup[name=main,maxpri=10]       [Ljava.lang.StackTraceElement;@53bc4411   after sleep(1500) Is held by Current Thread - true  
Next TopicJava ReentrantLock

You may also like