How Can You Determine If Your Program Has a Deadlock in Java ?

If we suspect that our application is stuck due to a Deadlock, then we just take a thread dump by using the command specific to environment in which your application is running. Eg. In Linux you can use command kill -3.

In case of deadlock, you will see in thread dump the current status and stack trace of threads in the JVM, and one or more of them will be stuck with message deadlock.

Also you can do this programmatically by using the ThreadMXBean class that ships with the JDK.

If you don't need programmatic detection you can do this via JConsole. On the thread tab there is a "detect deadlock" button.



You May Interest

Why Did Oracle Release a New Version of Java Like Java 8 ?

How Can Be Read Data From a Form in a JSP ?

What are the Rules of Method Overloading and Method Overriding in ...

What is a Singleton Class in Java ?

What is the Difference Between Expression and Scriptlet in JSP ?