import java.util.*;class Widget...{}
class WidgetMaker extends Thread...{
    ArrayList finishedWidgets=new ArrayList();
    public void run(){
        try{
            while(true){
                Thread.sleep(5000);//act busy
                                                
                synchronized(this){
                    finishedWidgets.add(w);
                    notify(); 
                }
            }
        }
        catch(InterruptedException e){}
    }
    
    public Widget waitForWidget(){
        synchronized(this){
            if(finishedWidgets.size()==0){
                try{
                    wait();
                }
                catch(InterruptedException e)
                {}
            }
            return (Widget)finishedWidgets.get(0);
        }
    }
}
public class WidgetUser extends Thread{
    private WidgetMaker maker;
    public WidgetUser(String name,WidgetMaker maker){
        super(name);
        this.maker=maker;
    }
    public void run(){
        Widget w=maker.waitForWidget();
        System.out.println(getName()+"got a widget");
    }
        public static void main(String[] args) {
        WidgetMaker maker=new WidgetMaker();
        maker.start();
        new WidgetUser("Lenny",maker).start();
        new WidgetUser("Moe",maker).start();
        new WidgetUser("Curly",maker).start();    }}
这是网上找的一个例子,他本来是用sychronized(finishedWidgets)的,但我改成this后,发现使用notify()与notifyAll()效果一样,都是把全部的wait线程唤醒。
不知有没有高人知道是怎么回事。