子线程结束后返回值给主线程

来源:互联网 发布:淘鹊桥和淘宝联盟 编辑:程序博客网 时间:2024/05/20 11:49
public interface Notify{
  public void perform(result);
}

public class MainThread implements Notify{
 public synchronized void perform(result){
   System.out.print(result);
 } 

 public void doCal(){
  new SubThread(this).start();
 }
}

public class SubThread extends Thread{
 private Notify notify;
 public SubThread(Notify notify){
   this.notify = notify;
 }

 public void run(){
   .....
   notify.perform(result);
 }
}
原创粉丝点击