GrzegorzM
GrzegorzM

Reputation: 842

How to check is any thread waiting on condition variable?

I have Condition variable named cond.

Is there any method which could give me true or false if there is any thread awaiting on cond?

I need something like: Boolean cond.isAwaitingSetEmpty()

Thanks for help

Upvotes: 1

Views: 2747

Answers (2)

Brian Roach
Brian Roach

Reputation: 76908

It's available from the Lock that the Condition is bound to:

http://download.oracle.com/javase/6/docs/api/java/util/concurrent/locks/ReentrantLock.html

For example:

getWaitingThreads(Condition condition) 
getWaitQueueLength(Condition condition) 

etc.

Upvotes: 0

axtavt
axtavt

Reputation: 242726

If by "condition" you mean a Condition created by ReentrantLock.newCondition(), then you can use ReentrantLock.hasWaiters(Condition cond).

Upvotes: 4

Related Questions