Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding waiting objects

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?

like image 211
er4z0r Avatar asked Apr 25 '26 22:04

er4z0r


1 Answers

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:

enter image description here

like image 120
noahlz Avatar answered Apr 28 '26 12:04

noahlz