• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Count of waiting threads

 
Norm Radder
Ranch Hand
Posts: 707
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to get a count of threads that are waiting on an object's monitor?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not aware to get that when one uses synchronized block. However, if you are using ReentrantLock then getQueueLength() will give you what you want.
 
Norm Radder
Ranch Hand
Posts: 707
3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Ajay Saxena
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there's no way to know ,from within a Java program,the size of the wait set (the set containing the threads waiting on the mutex) of an object's monitor when the synchronized block is used,the reason being the fact that the implementation of the synchronization logic,achieved through the synchronized keyword,is internal to the JVM. However it would have been good to have a native method on the java.lang.Object class that could return this wait set count.
[ September 04, 2008: Message edited by: Ajay Saxena ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic