• 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

Threads state

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Blocked state
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Blocked
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope! It is blocked.

See JDK API

This will prove it.

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic