代码:import java.util.ArrayList;
import java.util.Random;
public class Road {
public String name;//
ArrayList< String> cars=new ArrayList<String>();
public Road(String name) {
super();
this.name = name;
Thread th1=new Thread(new Runnable() {
@Override
public void run() {
for(int i=0;i<1000;i++)
{
try {
Thread.sleep((new Random().nextInt(10) + 1) * 1000);
//System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
cars.add(Road.this.name+"car"+i);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
th1.start();
Thread th2=new Thread(new Runnable() {
int count;
@Override
public void run() {
System.out.println(cars.size());
while(true)
{
if(cars.size()>0)
{boolean flag=lamp.valueOf(Road.this.name).islight;
if(flag)
{
System.out.println(cars.remove(0));
}
}
}
}
});
th2.start();
}
}
哪里错了啊,求指导
|