This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

next thread which will run a synchronized blocked method  RSS feed

 
A Ridolfi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Simple question: Imagine I have a synchronized method in a class, and a thread has blocked it. There are 4 threads waiting to use that method, after it returns. Upon the method return, which thread will get it first? The first thread that was waiting, or there is no guaranteed order?

Thank you,
Alberto M.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The behavior of favoring the longest waiting thread while giving lock acquisition is called fairness.
This is not supported by java monitor locks, however, the java concurrent util libraries provide ReentrantLocks and other utilities that provides an optional support for fairness. There are a few fine prints that you must see in the javadocs before using it
[ June 09, 2008: Message edited by: Nitesh Kant ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!