日期:2014-05-18 浏览次数:20733 次
public class Stack { LinkedList list = new LinkedList(); public synchronized void push(Object x){ synchronized(this){ list.addLast(x); notify(); } } public synchronized Object pop() throws Exception{ synchronized(this){ if(list.size() <= 0){ wait(); } return list.removeLast(); } } public static void main(String[] args) { } }
public synchronized Object pop() throws Exception{ synchronized(this){ if(list.size() > 0){ return list.removeLast(); } } return pop(); }
------解决方案--------------------