Site icon WebArtDeveloper

How to Perform Thread Communication in Multiple Threads in Core Java

In this tutorial how to perform Thread Communication in Multiple Threads in Core Java  is shown.

 

Code:

Thread7.java

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

public void run()
{
a1();
}
}

class B extends Thread
{
synchronized void b1()
{
System.out.println(“b1 is called”);
A a = new A();
notify();
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/rOeOlT-Ug0U

Exit mobile version