Java ReentrantLock isHeldByCurrentThread() MethodThe isHeldByCurrentThread() method of ReentrantLock Class checks if the current thread occupies this lock. SyntaxParameterNo parameter is passed. Returnstrue if current thread holds this lock and false otherwise ThrowsNo Exception is thrown. Example 1Test it NowOutput: 0 Thread-0 1 Thread-0 4 5 5 5 after sleep(1500) Is held by Current Thread - true task name - Job1 work done Example 2Test it NowOutput: 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;@6bd19be0 after sleep(1500) Is held by Current Thread - true task name - Job1 work done
Next TopicJava ReentrantLock
|