Search code examples
javamultithreadingsleep

How to check if a thread is sleeping?


Is there any way to check if a given thread is sleeping?


Solution

  • You can call Thread.getState() on and check if the state is TIMED_WAITING.

    Note, however that TIMED_WAITING doesn't necessarily mean that the thread called sleep(), it could also be waiting in a Object.wait(long) call or something similar.