public void callB(){
B b=new B(this);
b.start();
C c=new C(b);
c.start();
//加上b.join()或者c.join(),让主线程等待相应的子线程结束
try {
c.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
B b=new B(this);
b.start();
C c=new C(b);
c.start();
//加上b.join()或者c.join(),让主线程等待相应的子线程结束
try {
c.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class Call{
public static void main(String args[]){
new Call();
}
public Call(){
A a=new A(this);
synchronized(this){
a.callB();
try {
wait();
System.out.println("call");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("return message is "+a.getMessage());
}
}
String message;
Call call=null;
public A(Call call){
this.call=call;
}
public void callB(){
System.out.println("callB()");
B b=new B(this);
b.start();
C c=new C(b,call);
c.start();
}
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message=message;
}}