Patricia Shanahan <pats@acm.org> writes:
Gordon Beaton wrote:
On Sat, 12 May 2007 23:12:33 +0800, Yao Qi wrote:
The notify method will wake up one thread waiting to reacquire the
monitor for the object. How could I know which thread is waken up by
this notify method called by another thread?
I looked at java.lang.management.* and JVMTI, but I could not find a
feasible way to achieve this. I could not find answer from google
either.
The thread that gets woken up will know.
Or at least each thread knows when it wakes up, but not necessarily
which caller of notify caused it to wake up.
It might help to describe the higher level objective. If it matters
which one gets woken up, why are they all waiting for the same monitor?
Would it be enough to have each thread put a message, identifying
itself, on a queue when it gets woken?
We are writing a tool to check the events among threads in the
application, and synchronization event is one of these events. We want
to know something like this, Thread A calls notify() and then Thread B
is waken up from wait() by Thread A.
There is a concept "wait set" in JVM spec,
http://java.sun.com/docs/books/jvms/second_edition/html/Threads.doc.html#21294
and could we get the information of "wait set"?