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

Threads state

 
Girish Nagaraj
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume that a set of threads are accessing the same object in synchronization.

What will be the state of other threads when one of thread has acquired Lock of that object?
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blocked state
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blocked
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What will be the state of other threads when one of thread has acquired Lock of that object?


Won't the thread be in waiting state
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope! It is blocked.

See JDK API

This will prove it.

 
Pramila Chinguru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
There are only five states a thread can be in.
new,runnable,running,blocked,dead.
Blocked state includes when a thread is put to sleep using sleep method, or when a thread is waiting for an object lock is blocked using wait/notify protocol.
Go through this tutorial. Hope that helps.
 
Ashok S Yadav
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pramila,
The link that you have inserted in your message takes me to a page that says that a thread can be in one of the four states:
1. New
2. Runnable
3. Dead
4. Blocked.
Any thoughts on this. I am working my 1.4 certification. Thread is one topic that is really giving me headaches.

Thanks
 
Pramila Chinguru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ashok,
Any thread which is ready for execution(waiting for CPU time) would be kept in runnable pool. Once it gets CPU time(currently executing) then it is in Running state.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic