While going through some problems on internet, I found this one. Not sure how to solve this.I want thread-1 to run first and compute foo and wait, then want thread-2 to run and compute foo and finally want thread-1 to continue and print foo and complete execution.I am thinking about it since last 1 hour and not able to solve. Any help is appreciated. Thanks.\[code\]public class ThreadTest { private static class Thread01 extends Thread { private Thread02 _thread02; public int foo = 0; public void setThread02(Thread02 thread02) { _thread02 = thread02; } public void run() { try { for (int i = 0; i < 10; i++) foo += i; synchronized (this) { this.notify(); } synchronized (_thread02) { _thread02.wait(); } System.out.println("Foo: " + _thread02.foo); } catch (InterruptedException ie) { ie.printStackTrace(); } } }private static class Thread02 extends Thread { private final Thread01 _thread01; public int foo = 0; public Thread02(Thread01 thread01) { _thread01 = thread01; } public void run() { try { synchronized (_thread01) { _thread01.wait(); } foo = _thread01.foo; for (int i = 0; i < 10; i++) foo += i; synchronized (this) { this.notify(); } } catch (InterruptedException ie) { ie.printStackTrace(); } } } public static void main(String[] args) throws Exception { Thread01 thread01 = new Thread01(); Thread02 thread02 = new Thread02(thread01); thread01.setThread02(thread02); thread01.start(); thread02.start(); thread01.join(); thread02.join(); }}\[/code\]