Home » Java ReentrantLock isLocked() Method

Java ReentrantLock isLocked() Method

by Online Tutorials Library

Java ReentrantLock isLocked() Method

The 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.

Syntax

Parameter

No parameter is passed.

Returns

true if any thread holds this lock and false otherwise

Throws

No exception is thrown

Example 1

Test it Now

Output:

Thread Created.....  Thread Created.....  Thread Created.....  Thread Created.....   after sleep(1500) Is locked - true  task name - Job1 work done  

Example 2

Test it Now

Output:

  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

You may also like