Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Threads state

 
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?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blocked state
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blocked
 
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.

 
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.
 
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic