How does Deadlock Occur in Multiple Threads in Core Java

In this tutorial how does deadlock occur in Multiple Threads in Core Java is shown.

Code:

Thread6.java

class A extends Thread
{
synchronized void a1()
{
System.out.println(“a1 is called”);
B b = new B();
b.b1();
}
public void run()
{
a1();
}
}

class B extends Thread
{
synchronized void b1()
{
System.out.println(“b1 is called”);
A a = new A();
a.a1();
}
public void run()
{
b1();
}
}

class ThreadDemo
{
public static void main(String args[])
{
A t1 = new A();
B t2 = new B();
t1.start();
t2.start();
}
}

https://youtu.be/AEEp3gM6l3U

Add a Comment

Your email address will not be published. Required fields are marked *