How can I print all thread states?
The following code works fine but i am having trouble working with the Enum that is returned from getState(). In the following i guess the Enum returned will always contain just one element since a thread can only be in one state at a time.
Code:
public static void ThreadState(Thread t){
Enum e = t.getState();
System.out.println(t.getName() + " is " + e.name());
}
but how can i print out all the states? Enum defines
Code:
static Thread.State[] values()
I have the following......
Code:
Enum e = t.getState();
Thread.State[] ts = e.values();
t is simply a Thread instance but the compiler says that e has no values() method.
Re: How can I print all thread states?
Got it but a bit confused. If getState() is supposed to return an Enum of thread states then how is it possible to assign the Enum to a single Thread.State? Is it because a thread can only be in a single state at a time?
Code:
Thread t = new Thread();
Thread.State e = t.getState();
Thread.State[] ts = e.values();
for(int i = 0; i < ts.length; i++){
System.out.println(ts[i]);
}