aspose file tools*
The moose likes Threads and Synchronization and the fly likes Thread.State.NEW Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread.State.NEW" Watch "Thread.State.NEW" New topic
Author

Thread.State.NEW

Sankaranarayanan Viswanathan
Greenhorn

Joined: Sep 27, 2011
Posts: 5


The above code gives the following output on my machine. Can someone help me understand how the output of Self State can ever be NEW? Per my understanding NEW is only when a thread has not yet been started.

State 1: NEW
State 2: RUNNABLE
State 3: BLOCKED
Self State 1: NEW
Self State 2: NEW
State 4: WAITING
Self State 3: NEW
State 5: TERMINATED
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

The getState() call inside the run() method returns the state of the ClassA instance you've passed to the Thread constructor.
That Thread instance will never actually run, it will just have its run() method called.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread.State.NEW
 
Similar Threads
Thread - Wait() and Notify();
problem with wait,notify
Thread Communication using wait() and notify()
Deadlock with Java Threads
final void notifyall():Wakes up all threads that are waiting for this objects lock.