Home » Java ReentrantLock hasQueuedThreads() Method

Java ReentrantLock hasQueuedThreads() Method

by Online Tutorials Library

Java ReentrantLock hasQueuedThreads() Method

The hasQueuedThreads() returns a boolean value true or false depending upon whether any threads are waiting to acquire this lock. Note that because cancellations may occur at any time, a true return does not guarantee that any other thread will ever acquire this lock.

Syntax

Parameter

No parameter is passed.

Returns

true if there may be other threads waiting to acquire the lock

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.   has queued Threads = false  Thread-1 has released the lock.  

Example 2

Test it Now

Output:

Thread-1 is Waiting to get the lock  Thread-1 has got the  lock.  Thread-2 is Waiting to get the lock  Thread-3 is Waiting to get the lock   has queued Threads = true  Thread-1 has released  the lock.  Thread-2 has got the  lock.   has queued Threads = true  Thread-2 has released  the lock.  Thread-3 has got the  lock.   has queued Threads = false  Thread-3 has released  the lock.  
Next TopicJava ReentrantLock

You may also like