89
Java Reentrant getQueueLength() Method
The 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.
Syntax
Parameter
No parameter is passed.
Returns
the estimated number of threads waiting for this lock
Throws
No Exception is thrown.
Example 1
Output:
Thread-1 has released the lock. getQueueLength = 0
Example 2
Output:
ThreadB has got the lock. getQueueLength = 2 ThreadA has got the lock. getQueueLength = 1 ThreadC has got the lock. getQueueLength = 0
Next TopicJava ReentrantLock