Java ReentrantLock lockInterruptibly() MethodThe lockInterruptibly() method of ReentrantLock class hold the lock until or unless the current thread is interrupted. SyntaxParameterNo parameter is passed. ReturnsNA ThrowsInterruptedException - if the current thread is interrupted Example 1Test it NowOutput: 0 Thread-0 1 Thread-0 4 5 Example 2Test it NowOutput: 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
|