Java ReentrantLock toString() MethodThe toString() method of ReentrantLock Class returns a string identifying this lock and its lock state. SyntaxParameterNo parameter is passed. ReturnsA string identifying this lock, as well as its lock state ThrowsNo Exception is thrown. Example 1Test it NowOutput: 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 2Test it NowOutput: 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
|