aspose file tools*
The moose likes Threads and Synchronization and the fly likes Count of waiting threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Count of waiting threads" Watch "Count of waiting threads" New topic
Author

Count of waiting threads

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
Is there a way to get a count of threads that are waiting on an object's monitor?
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

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.


apigee, a better way to API!
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 686
Thanks.
Ajay Saxena
Ranch Hand

Joined: Nov 13, 2006
Posts: 154
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Count of waiting threads