Home » Java ReentrantLock toString() Method

Java ReentrantLock toString() Method

by Online Tutorials Library

Java ReentrantLock toString() Method

The toString() method of ReentrantLock Class returns a string identifying this lock and its lock state.

Syntax

Parameter

No parameter is passed.

Returns

A string identifying this lock, as well as its lock state

Throws

No Exception is thrown.

Example 1

Test it Now

Output:

[email protected] Thread-0 Thread-0 Thread-0 Thread-0 Thread-0 Thread-0   [email protected][Running, pool size = 1,    active threads = 1, queued tasks = 0, completed tasks = 0] Thread-0 task name - Job1 releasing lock(outer lock) Lock Hold Count - 0 

Example 2

Test it Now

Output:

[email protected][Unlocked]   [email protected] Thread-1 is Waiting to get the lock      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;@12a128ac  after sleep(1500) Is held by Current Thread - true 
Next TopicJava ReentrantLock

You may also like