Drop Down

Tuesday, January 22, 2019

Multithreading:: InterProcess Communication

package multithreading;

public class ThreadA
{
public static void main(String[] args) throws InterruptedException
{
ThreadB b = new ThreadB();
b.start();
synchronized (b)
{
  b.wait();
}
System.out.println("Total: "+ b.sum);
}
}

class ThreadB extends Thread
{
int sum =0;
public void run()
{
for(int i=1;i<100;i++)
{
sum = sum+i;
}
synchronized(this)
{
this.notify();
}
}

}

No comments:

Post a Comment

Java 8 Notes Pics