Java ReentrantLock getOwner() MethodThe 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. SyntaxParameterNo parameter is passed. Returnsthe owner, or null if not owned ThrowsNo Exception is thrown. Example 1Test it NowOutput: Thread-0: lock1 owner: Thread-0 Example 2Test it NowOutput: 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
|