aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem with kathy sierra book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Problem with kathy sierra book" Watch "Problem with kathy sierra book" New topic
Author

Problem with kathy sierra book

Jacob Sonia
Ranch Hand

Joined: Jun 28, 2009
Posts: 174
When the sleep or wait is over, or an object's lock becomes available, the
thread can only reenter the runnable state. It will go directly from waiting to
running (well, for all practical purposes anyway).

It should be that it will not directly from waiting to running
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Runnable state is the very first state in Threads life cycle and thats too comes once, when object get instantiated. Once the run() method gets called, it becomes running.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Juri Smolarek
Greenhorn

Joined: Jan 30, 2010
Posts: 11
Sagar Rohankar wrote:Runnable state is the very first state in Threads life cycle and thats too comes once, when object get instantiated. Once the run() method gets called, it becomes running.


First state is "new", "runnable" is 2nd.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Jacob you are write the thread goes to runnable state not running state. It should be misprint.


A thread will have 4 stages in its lifecycle:

new ---> runnable------>running-------->dead

the fifth stage which may come is waiting/blocking state after which it goes back to runnable state.

new comes only once and after the thread is dead no other states can ever come.


SCJP 1.6 96%
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Juri Smolarek wrote:
Sagar Rohankar wrote:Runnable state is the very first state in Threads life cycle and thats too comes once, when object get instantiated. Once the run() method gets called, it becomes running.

First state is "new", "runnable" is 2nd.

When you create "new" Thread, its become "runnable".
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

Sagar Rohankar wrote:When you create "new" Thread, its become "runnable".

AFAIK, this is not true. When you instantiate a thread, its not runnable. The way I know it, is that a thread is runnable when it has been started (using start method) but it is actually not running i.e. the CPU isn't executing it at this point in time. The thread may switch between runnable and running state multiple times during its lifetime which we don't have to worry about most of the times. The yield method is used to make a running thread runnable...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Juri Smolarek
Greenhorn

Joined: Jan 30, 2010
Posts: 11
nope! (nope to Sagar Rohankar 14:27:41)
page 708

invoking start() changes state to runnable
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

I'm confused in "running" and "runnable" state. I gone with the simple English which forced me to conceive "runnable" means the "the thread has ability to run(execute), but isn't executing at the time" and "running" means running.
But in Java, "runnable" means "running".. So I understood my mistake, thank you for pointing me out.
Juri Smolarek
Greenhorn

Joined: Jan 30, 2010
Posts: 11
runnable means: thread has the ability to be executed by the scheduler. but there is no guarantee, that scheduler will comes immediately. if he does not, that's the gap between runnable and running. if he does, state will be changed to running.
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
Sagar Rohankar wrote:I'm confused in "running" and "runnable" state. I gone with the simple English which forced me to conceive "runnable" means the "the thread has ability to run(execute), but isn't executing at the time" and "running" means running.
But in Java, "runnable" means "running".. So I understood my mistake, thank you for pointing me out.


your understanding is right runaable means a thread has ability to run that is to come to running state, but when will it come to running state depends upon scheduler.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ohh.. How come I missed that "scheduler" part,.. Crystal clear now. Thanks to everyone. Gotta brush up some Thread things.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with kathy sierra book