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);
}
}
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);
}
}
本文深入探讨了Java中多线程环境下通过Notify接口实现线程间通信和通知的基本原理及应用实例,包括主线程启动子线程、子线程执行任务并调用Notify接口触发主线程进行特定操作的过程。
578





