This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso on-line!
See this thread for details.
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

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Thread.State.NEW" Watch "Thread.State.NEW" New topic


Sankaranarayanan Viswanathan

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 3: BLOCKED
Self State 1: NEW
Self State 2: NEW
State 4: WAITING
Self State 3: NEW
Jelle Klap

Joined: Mar 10, 2008
Posts: 1894

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.
Have you tried LearnNowOnline?
subject: Thread.State.NEW