I notice there is no isWaiting() method. Is it possible to test whether any thread is blocked wait()ing on a specific object? Given a Thread object, is it possible to find which object, if any, that Thread is wait()ing on?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, for the waiting state try
thread.getState() == Thread.State.WAITING || thread.getState() == TIMED_WAITING.As for the object the thread waits for, I’m not sure but I doubt you could get the object the thread is wating for without native code. The otherway round, i.e. getting the thread which holds a lock on a given object, also seems to be impossible with pure Java (see here: Programmatically determine which Java thread holds a lock).