Is there a way to get a list of waiting threads/number of waiting threads on an object?
If you are using the synchronized
keyword - no. But if you are using the java.util.concurrent
locks, you can.
ReentrantLock
has a protected method getWaitingThreads()
. If you extend it, you can make it public.
Update: You are using .wait()
and .notify()
, so you can manually fill and empty a List
- before wach .wait()
call list.add(Thread.currentThread()
, and remove it before each notify. It's not perfect, but actually you shouldn't need such a list.