Java ReentrantLock isLocked() MethodThe isLocked() method of ReentrantLock class checks if any thread occupies this lock. This method is created for use in monitoring of the system state, not for synchronization control. SyntaxParameterNo parameter is passed. Returnstrue if any thread holds this lock and false otherwise ThrowsNo exception is thrown Example 1Test it NowOutput: Thread Created..... Thread Created..... Thread Created..... Thread Created..... after sleep(1500) Is locked - 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;@3127c164 after sleep(1500) Is held by Current Thread - true task name - Job1 work done
Next TopicJava ReentrantLock
|