Java - How to know when thread is waiting?

java, multithreading

Solution

The method `getState()` of a thread returns a `Thread.State` which can be:

NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING or TERMINATED

See Thread.State.

Problem

Is there any neat solution of knowing when a thread has been put into `wait` status? I am putting threads to `wait` and I `notify` them when i need it. But sometimes I want to know if a thread is currently waiting, and if so, I have to do something else. I could probably set a flag myself to true/false. But I can't imagine there is a better way to do this?

Original source