File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread's sleep  method will result in un-runnable state? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Watch "Thread New topic
Author

Thread's sleep method will result in un-runnable state?

Kay Liew
Ranch Hand

Joined: Dec 26, 2003
Posts: 112
I need confirmation on this. Somewhere in Dan's online mock, I ran into this question. Well, to keep the question short here is the version of it.

Choice # 1 - The Thread.sleep method causes the thread to move to the Not-Runnable state

Choice # 2 - The Thread.sleep method causes the thread to move to the Ready state

Which one is the correct choice ? To me, Not-Runnable means dead and Ready means before the run method is call. I have chosen #2 because sleep will wake up and when it got up it will be in the thread pool and waiting for its lucky queue. While Dan's answer was the #1, which means after invoking sleep the thread is dead and while if a thread is dead it cannot be re-started.

Thx in adv.
k


Unity can only be manifested by the Binary. Unity itself and the idea of Unity are already two.
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
#1 is correct.
Not-Runnable state doesn't mean dead state. After sleep time is complete, it will move to Ready state and will wait for its time for execution.


Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
Jay Pawar
Ranch Hand

Joined: Aug 27, 2004
Posts: 411
Kay,
The choice 1 is correct because the thread goes into non-runnable state in the following instances


1> Thread is blocked waiting for I/O resource or the object's lock .
2> The thread's run method might tell to sleep for some time.
3> The thread may be waiting because the thread's method called wait() method.



So I feel, not runnable means Waiting/blocking/sleeping that is what Dan Chisholm meant too.

Hope this helps ya.


Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Anand Ko
Ranch Hand

Joined: Dec 03, 2003
Posts: 79
To add
- if Thread is calling join on another thread, it goes to non-runnable state
Francis Palattao
Ranch Hand

Joined: Sep 22, 2004
Posts: 91
Please correct me if I'm wrong is ready state and runnable state the same?


SCJP 1.4 <br />SCWCD 1.4 (preparing)<br />SCBCD 1.3 (coming soon)
Kay Liew
Ranch Hand

Joined: Dec 26, 2003
Posts: 112
Francis,

That's what i thought. Runnable is the same as ready which waiting in the thread pool and gets it lucky queue.

Further clarification on this would be great.

Thx again.
k
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread's sleep method will result in un-runnable state?