读书人

Java之wait()跟notify()

发布时间: 2014-03-19 16:42:03 作者: rapoo

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代码块执行完成之后才能释放锁

读书人网 >网络基础

热点推荐