barrybao

Thread.wait

Today, I tried to wirte some code to test thread. Use a Schedular to controll thread's running. For thread: public class ControllerThread extends Thread { public void run() { ... Schedular.waitForOthers(this); ... } } In Schedular public class Schedular { public static synchronized void waitForOthers(ControllerThread thread) throws InterruptedException { waitingThreadNum++; // waitingThreadNum is a counter. if (waitingThreadNum != threads.size()) { System.out.println("Thread:" + thread.getName() + " is going to wait"); wait(); // thread.wait() is useless here } else { waitingThreadNum = 0; System.out.println("All threads will run"); notifyAll(); } } } Is there anybody know why thread.wait cannot work in Schedular?

posted on 2006-04-17 23:44 以苦为乐 阅读(339) 评论(0)  编辑  收藏 所属分类: j2se


只有注册用户登录后才能发表评论。


网站导航: