Sunday, 15 January 2017

How to find whether a deadlock has occurred in Java? How to detect a Deadlock in Java?

Since JDK 1.5 there are some powerful methods added in the java.lang.management package to diagnose and detect deadlocks. The java.lang.management.ThreadMXBean interface is management interface for the thread system of the Java virtual machine. It has two methods to detect deadlock in a Java application

     findMonitorDeadlockedThreads() – This method can be used to detect cycles of threads that are in deadlock waiting to acquire object monitors. It returns an array of thread IDs that are deadlocked waiting on monitor.


     findDeadlockedThreads() – It returns an array of thread IDs that are deadlocked                    waiting on monitor or own able  synchronizers.

No comments:

Post a Comment