86
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
Output:
0 Thread-0 1 Thread-0 4 5
Example 2
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