简体   繁体   中英

What free tools are available to analyze lock contention in java?

I need to determine which locks are the most-contended-for in my application code. What free tools can I use to determine this ?

you can use jconsole or jstack both in the bin directory of your JDK. The jconsole in particular allows you to connect to your process and monitor the threads including which resources they have locked, and it can help you identify a deadlock state.

You can also view this in eclipse's debugger. In the Debug view, use the little down-triangle menu on the view toolbar to turn on "Java->Show Monitors".

When you suspect a deadlock, pause the application (select the application in the debug view and press the pause button on the debug view toolbar) and if there's a deadlock, the blocking threads will turn red. If you expand those threads you can see the lock contention.

VisualVM(Java 1.6的一部分)( 参见参考资料)

The JDK has some built-in support - under unix, kill -3 the process, under windows, ctrl-break. This will display a complete thread dump, followed by any deadlocks detected. Plus, in the thread dusmp you can see what threads own what locks, and compare them to each other.

If you own the code, you could create/look for a Lock implementation which gathers contention statistics. If not, try the tools suggested in the other posts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM