• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread states in Java 5

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mike for your valuable explanation, now got your point.
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic