Java多线程 sycronize - wait -notify - notifyall

 1 package com.common.test;
 2 
 3 import java.util.LinkedList;
 4 
 5 class Stack     
 6 {        
 7      LinkedList list = new LinkedList();     
 8     
 9     public synchronized void push(Object x)     
10     {   
11         synchronized(list) {  
12             list.addLast( x );               
13             notifyAll();
14        }     
15      }     
16     
17     public synchronized Object pop() throws InterruptedException     
18     {   
19         synchronized(list)  {
20             while( list.size() <= 0 ) { 
21                 wait();
22             }
23             return list.removeLast();     
24         }     
25    }     
26      
27  }  
28 

看看这段代码有什么问题?

原文地址:https://www.cnblogs.com/zhangxz/p/1807385.html