Results 1 to 2 of 2

Thread: How can I print all thread states?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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.

  2. #2

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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]); 
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width