110,536
社区成员
发帖
与我相关
我的任务
分享
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();
}