Home » Java ReentrantLock getQueuedThreads() Method

Java ReentrantLock getQueuedThreads() Method

by Online Tutorials Library

Java Reentrantlock getQueuedThreads()Method

The getQueuedThreads() returns a collection containing threads that may be waiting to acquire this lock. Because the actual threads may change dynamically while constructing this result, the returned collection is only a best-effort estimate.

Syntax

Parameter

No parameter is passed.

Returns

the collection of threads

Throws

No Exception is thrown.

Example 1

Test it Now

Output:

Thread-1 is Waiting to get the lock  Thread-1 has got the lock.   getQueueLength = 0    Thread-1 has released the lock.  

Example 2

Test it Now

Output:

Thread-1 is Waiting to get the lock  Thread-3 is Waiting to get the lock  Thread-1 has got the lock.  Thread-2 is Waiting to get the lock  getQueueLength = 2  Thread-1 has released the lock.  Thread-3 has got the lock.  getQueueLength = 1  Thread-3 has released the lock.  Thread-2 has got the lock.  getQueueLength = 0  Thread-2 has released the lock.  
Next TopicJava ReentrantLock

You may also like