public class TestNotify {
public static void main(String[] args) {
TestNotify testNotify = new TestNotify();
MyThread t = testNotify.new MyThread();
t.start();
System.out.println("MyThread is start.");
synchronized (t) {
try {
System.out.println("Waiting for b to complete.");
t.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("MyThread is stop.");
}
}
class MyThread extends Thread {
public int total;
public void run() {
synchronized (this) {
System.out.println("MyThread is running...");
for (int i = 0; i < 100; i++) {
total += i;
}
System.out.println("fianl total is:" + total + ".");
notify();
}
}
}
}