62,614
社区成员
发帖
与我相关
我的任务
分享
public class Consumer extends Thread
{
private List list;
public Consumer(List list)
{
this.list = list;
}
public void run()
{
synchronized (list)
{
while (list.size() == 0)
{
try
{
list.wait(); //为什么不能用this.wait()
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
list.remove(0);
try
{
Thread.sleep(2000); //为什么不能用this.sleep
}
synchronized (list)