Java ReentrantLock hasQueuedThread() MethodThe hasQueuedThread(Thread thread) method of ReentrantLock class returns true if there is some thread is waiting for the this lock. Note that because cancellations may occur at any time, a true return does not guarantee that this thread will ever acquire this lock. This method is designed primarily to use in monitoring of the system state. SyntaxParameterthread - the thread Returnstrue if the given thread is queued waiting for this lock ThrowsNullPointerException - if the thread is null. Example 1Test it NowOutput: Thread-1 is Waiting to get the lock Thread-1 has got the lock. has queued Thread = false Thread-1 has released the lock. Example 2Test it NowOutput: Thread-2 is Waiting to get the lock Thread-3 is Waiting to get the lock Thread-1 is Waiting to get the lock Thread-2 has got the lock. has queued Thread = false Thread-2 has released the lock. Thread-3 has got the lock. has queued Thread = false Thread-3 has released the lock. Thread-1 has got the lock. has queued Thread = false Thread-1 has released the lock.
Next TopicJava ReentrantLock
|