Reputation: 4901
We profiled our application with jvisualvm and found out that it spends a lot of time in Object.wait().
How do I find the objects that this method is called for?
Upvotes: 3
Views: 117
Reputation: 48060
If you're not restricted to jvisualvm, in JProfiler you can right-click the object in the locking graph and inspect it in the heap walker.
This is for the current locking situation, but the history views will give you access to previous locking situations and there is also a monitor statistics view that will break down the monitors by their class:
Disclaimer: My company develops JProfiler.
Upvotes: 1
Reputation: 10311
In fact, the Java SE SDK comes with a useful class ThreadInfo which you can inspect to learn why a thread is blocked and what it is waiting on, including the full stacktrace to the wait point, and the total time in millis spent waiting.
You use this class via the java.lang.management
package and specifically ManagementFactory.getThreadMXBean()
You can then use this class to inspect your blocked threads programmatically.
Here is a relevant screenshot from JConsole:
Upvotes: 1
Reputation: 105123
Hanging on Object.wait()
is a totally legal and safe situation, which may happen, for example, when some thread is waiting for a new element in a BlockingQueue
. The time spent on this waiting shouldn't affect performance of your application, unless it's a deadlock.
Upvotes: 0