File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread states in Java 5

 
Kalyan Anand
Ranch Hand
Posts: 194
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per K&B for Java 5 a thread can be in the following states
New
Runnable
Running
Waiting/blocked/sleeping
Dead

In the Java 5 API we have the following states
* NEW
* RUNNABLE
* BLOCKED
* WAITING
* TIMED_WAITING
* TERMINATED

Given that the basic architecture of threads hasn't changed how do I compare these states with the states in K&B ?
[ September 08, 2008: Message edited by: Santhosh Jali ]
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
New = NEW
Runnable or Running = RUNNABLE
Blocked = BLOCKED
Waiting (with no timeout) = WAITING
Waiting (with timeout) or Sleeping = TIMED_WAITING
Dead = TERMINATED
 
kishore mang
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

I dont think Runnable and Running states are same as per your post.
Runnable = Thread.start() called
Running = run() method being executing


Regards
Kishore
 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't say they were the same. But both Runnable and Running map to Thread.State.RUNNABLE. RUNNABLE consists of everything Running plus everything that is Runnable.
 
kishore mang
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RUNNABLE consists of everything Running plus everything that is Runnable.


In most of the books it was mentioned as Runnable and Running are two different states, so cant be one part of the other.

Since When Thread.start() called CPU will schedule that thread but may not be running state, but when schedules and run() method called means
that thread is in running(using CPU and active) in conceptual manner. After sleeping() CPU will put in Runnable not compulsorily in Running(active).

So can we say now that a thread which is in Runnable is Running?


 
Mike Simmons
Ranch Hand
Posts: 3028
10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kishore mang wrote:In most of the books it was mentioned as Runnable and Running are two different states, so cant be one part of the other.

Runnable and Running are two different states, but Thread.State.RUNNABLE is a single state that includes both Runnable and Running. Look at the documentation for Thread.State. What value could a Runnable thread possibly have, based on their definitions there? Annd what value could a Running thread have? For both, the only possible answer is RUNNABLE.

kishore mang wrote:So can we say now that a thread which is in Runnable is Running?

Not using Thread's getState() method, no, you can't. The getState() method does not know or care about the difference between Runnable and Running.
 
kishore mang
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike for your valuable explanation, now got your point.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic