Javatpoint Logo
Javatpoint Logo

Java Thread holdLock() method

The holdLock() method of thread class returns true if the current thread holds the monitor lock on the specified object.

Syntax

Parameter

obj: It defines the object on which to test lock ownership

Return

It returns true if and only if the current thread holds the monitor lock on the specified object. Otherwise, it returns false.

Exception

NullPointerException: This exception throws if obj is null.

Example

Test it Now

Output:

Currently executing thread is: Thread-0
Does thread holds lock? false
Does thread holds lock? true






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