Javatpoint Logo
Javatpoint Logo

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:

com.app.Rentrant.toStringClass@7852e922
Thread-0
Thread-0
Thread-0
Thread-0
Thread-0
Thread-0
  java.util.concurrent.ThreadPoolExecutor@70dea4e[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:

java.util.concurrent.locks.ReentrantLock@7852e922[Unlocked]
  com.app.Rentrant.ToStringClass2@4e25154f
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





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