Java ReentrantLock hasQueuedThreads() MethodThe 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. SyntaxParameterNo parameter is passed. Returnstrue if there may be other threads waiting to acquire the lock ThrowsNo Exception is thrown. Example 1Test it NowOutput: 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 2Test it NowOutput: 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
|