Deadlock Sample Program Java
T1 acquiring lock on java.lang.Object@6d9dd520 t1 acquired lock on java.lang.Object@6d9dd520 t2 acquiring lock on java.lang.Object@22aed3a5 t2 acquired lock on java.lang.Object@22aed3a5 t3 acquiring lock on java.lang.Object@218c2661 t3 acquired lock on java.lang.Object@218c2661 t1 acquiring lock on java.lang.Object@22aed3a5 t2 acquiring lock on java.lang.Object@218c2661 t3 acquiring lock on java.lang.Object@6d9dd520 Here we can clearly identify the deadlock situation from the output but in real life applications it’s very hard to find the deadlock situation and debug them. How to Detect Deadlock in Java To detect a deadlock in java, we need to look at the of the application, in last post I explained how we can generate thread dump using VisualVM profiler or using jstack utility.
Here is the thread dump of above program.
See More On Tutorialspoint
DEADLOCK IN JAVA WITH EXAMPLE Deadlock involves a mutual interdependence between two or more threads. Let us consider an example program that deadlocks. Deadlock in java. Deadlock occurs in a situation where two or more threads are blocked forever, waiting for each other. Let's see its example.