日期:2014-05-20 浏览次数:20896 次
public class Test { Object o = new Object(); boolean b = false; public static void main(String[] args) { new Thread(new Thread1()).start(); new Thread(new Thread2()).start(); } private class Thread1 implements Runnable { public void run() { a(); } private void a() throws InterruptedException { synchronized(o) { if(b) { wait(); } //执行内容 } } } private class Thread2 implements Runnable { public void run() { b(); } private void b() throws InterruptedException { b = true; synchronized(o) { //执行内容 b = false; notify(); } } } }