• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronization

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends,
I wanted to know that when an method is synchronized then the thread executing that process continues uninterrupted, but the other threads which come meanwhile they have to wait for the current thread to terminate, now my question is :
What is the actual state of the threads which are waiting "in blocked state" or in some other state?
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just think about the classic deadlock scenario for your answer:
Each thread is BLOCKED while waiting to acquire the object lock (or monitor)
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anirban,
Your threads are offically in a wait state. That is, they are waiting to be notified by the monitor that it is free.
HTH,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi max and leslie,
Thanks for the answer. I wanted to know onw more thing that when the lock is released, who decides which thread is to enter next?
 
nitin kumar
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here
there are actually two aspects whether u are referring to the threads in the entry set or referring to the threads in the wait set. If at all there are threads in the entry set there will be a competition between the two threads one in entry set and one in wait set .But when a thread releases the lock then it is our design to consider which thread will become an active one.u might think that the thread waits the longest chosen to acquire the monitor
bye
nitin
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Max Habibi:

Your threads are offically in a wait state. That is, they are waiting to be notified by the monitor that it is free.

Max,
Can you clarify what you mean by wait state?
When threads are contending for a monitor using the synchronized mechanism, are any locks released while they are in this wait state as would be when calling wait() explicitly?
Thanks
[ August 26, 2002: Message edited by: Leslie Chaim ]
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Leslie Chaim:
Can you clarify what you mean by wait state?

Please see this
link.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!