When we us java Thread,Sometimes we nedd concurrent visit some resources, in this way,we have to use synchronized.
today what we will talk about is wait and notify.
first have a look at this fragment.
public Class A {
public static void main(String[]args) {
ThreadB b = new ThreadB();
b.start();
synchronized(b) {
System.out.println("waiting......");
b.wait();
}
System.out.println("result:"+b.getResult());
}
}
------------------------ThreadB-------------------------
public Class ThreadB extends Thread {
public void run() {
synchronized(this) {
......
notify();
}
}
}