Home » Java ReentrantLock getOwner() Method

Java ReentrantLock getOwner() Method

by Online Tutorials Library

Java ReentrantLock getOwner() Method

The getOwner() method of ReentrantLock class returns the current owner thread of the lock. It returns null if not owned. When this method is called by a thread that is not the owner, the return value reflects a best-effort approximation of current lock status.

Syntax

Parameter

No parameter is passed.

Returns

the owner, or null if not owned

Throws

No Exception is thrown.

Example 1

Test it Now

Output:

Thread-0: lock1 owner: Thread-0  

Example 2

Test it Now

Output:

 Thread-0: lock1 owner: Thread-0  Thread-0: lock2 owner: none  Thread-1: lock1 owner: Thread-0  Thread-1: lock2 owner: Thread-1  
Next TopicJava ReentrantLock

You may also like