Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

thread state  RSS feed

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




output is:


WAITING
TIMED_WAITING
TERMINATED
Runnable running
Runnable running
Runnable running
Runnable running
Runnable running


I didn't use wait() or join() or..

why does print WAITING?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised it doesn't print more than that. e.values() returns all the values of the Thread.State enum. It has nothing to do with the current state of your thread. What you want to do is :
 
amitabh mehra
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.State[] ts = e.values();

would return you an array of enum of Thread.State, and you are printing the same. These are not your "current thread" states.
Please check http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.State.htmlfor more info.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After the bold statement has been executed, clockThread is in the New Thread state. When a thread is a New Thread, it is merely an empty Thread object; no system resources have been allocated for it yet. When a thread is in this state, you can only start the thread. Calling any method besides start when a thread is in this state makes no sense and causes an IllegalThreadStateException. (In fact, the runtime system throws an IllegalThreadStateException any time a method is called on a thread and that thread's state does not allow for that method call.)


http://www.lkn.ei.tum.de/arbeiten/faq/man/JAVA-tutorial/essential/threads/lifecycle.html




I run this code without any problem.Then the above statement is wrong.Right?
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I wanted to see other state of thread,How could I do in that code?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:If I wanted to see other state of thread,How could I do in that code?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!