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();
}
}

Add a Comment

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