Java之wait()和notify()
public class TestConcurrentThread {public static final Object lock = new Object();public static List<String> list = new ArrayList<String>();public static void main(String[] args) {Thread customerThread = new Thread(new Customer());customerThread.start();Thread producerThread = new Thread(new Producer());producerThread.start();}}
结论:
1.有wait(),notify()的地方必须有synchronized
2.wait()之后必须通过notify()系唤醒
3.notify()系的时候需要在synchronized代码块执行完成之后才能释放锁