Javatpoint Logo
Javatpoint Logo

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

Test it Now

Output:

Thread-1 has released the lock.
 getQueueLength = 0  

Example 2

Test it Now

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





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