I want to check whether the thread is in 'wait state' inside an if loop. I find Thread.getState()
which returns NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING or TERMINATED
. But i am confused how it can be used in a loop because i do not know what value it returns. if (Thread.getState()==??)
what should come in place of ??. is it string 'WAIT'
.
Asked
Active
Viewed 15 times
0
-
1It's Enum. See https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.State.html – PM 77-1 Nov 14 '15 at 02:51
-
1*"I want to check whether the thread is in 'wait state' inside an if loop."* - Polling the state of something in a loop is probably a BAD IDEA. – Stephen C Nov 14 '15 at 03:06
-
Thank you but i am able to catch IllegalMonitorStateException so do not need this. i should have changed my question because i do not know my thread is in wait state or not. Now i do not have to bother about that. – Struse Nov 14 '15 at 03:21