Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kay Liew
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anand Ko
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#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.
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anand Ko
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add
- if Thread is calling join on another thread, it goes to non-runnable state
 
Fran Kindred
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please correct me if I'm wrong is ready state and runnable state the same?
 
Kay Liew
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic