Is there any way to check if a given thread is sleeping?
Here is an fairly ugly hack to check if the other thread is sleeping:
public static boolean isSleeping(Thread t) {
StackTraceElement[] ste = t.getStackTrace();
if (ste.length == 0)
return false; // thread has terminated!
return ste[0].getClassName().equals("java.lang.Thread")
&& ste[0].getMethodName().equals("sleep");
}