代码如下,为什么我打断点,断点不进push()方法?
public class Container {
//仓库
private List<Integer> list=new LinkedList<Integer>();
public static Integer maxSize=10;
public List<Integer> getList() {
return list;
}
public void setList(List<Integer> list) {
this.list = list;
}
/**
*
* 从仓库中拿
* @return
* @see [类、类#方法、类#成员]
*/
public synchronized Integer pop(){
synchronized (list) {
Integer num=null;
if(!list.isEmpty()){
num= list.remove(0);
System.out.println("移除了"+num);
list.notifyAll();
}else{
try {
list.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return num;
}
}
/**
*
* 推送到仓库中
* @param num
* @see [类、类#方法、类#成员]
*/
public synchronized void push(){
synchronized (list) {
Random random=new Random();
Integer num=random.nextInt(2);
if(list.size()<maxSize){
list.add(num);
System.out.println("添加了"+num);
list.notifyAll();
}else{
try {
list.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
final Container container=new Container();
Thread consume=new Thread(new Runnable() {
public void run() {
while(true){
container.pop();
}
}
});
Thread produce=new Thread(new Runnable() {
public void run() {
container.push();
}
});
consume.start();
produce.start();
}
}