Javatpoint Logo
Javatpoint Logo

Java ReentrantLock isHeldByCurrentThread() Method

The isHeldByCurrentThread() method of ReentrantLock Class checks if the current thread occupies this lock.

Syntax

Parameter

No parameter is passed.

Returns

true if current thread holds this lock and false otherwise

Throws

No Exception is thrown.

Example 1

Test it Now

Output:

    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 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;@6bd19be0
 after sleep(1500) Is held by Current Thread - true
task name - Job1 work done
Next TopicJava ReentrantLock





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA