Java Reentrant getQueueLength() MethodThe getQueueLength() method of ReentrantLock Class returns the number of threads waiting to get the lock. The value is approximate because the number of threads can change dynamically while traversing internal data structures. It is used to monitor the state. SyntaxParameterNo parameter is passed. Returnsthe estimated number of threads waiting for this lock ThrowsNo Exception is thrown. Example 1Test it NowOutput: Thread-1 has released the lock. getQueueLength = 0 Example 2Test it NowOutput: ThreadB has got the lock. getQueueLength = 2 ThreadA has got the lock. getQueueLength = 1 ThreadC has got the lock. getQueueLength = 0
Next TopicJava ReentrantLock
|