- public class Road {
- private List<String> vehicle = new ArrayList<String>();
- private String name = null;
- public Road(final String name){
- this.name = name;
- ExecutorService pool = Executors.newSingleThreadExecutor();
- pool.execute(new Runnable() {
- public void run() {
- for(int i =1;i<100;i++){
- try {
- Thread.sleep((new Random().nextInt(10)+1)*1000);
- } catch (InterruptedException e) {
-
- e.printStackTrace();
- }
- vehicle.add(name+"--"+i);
- }
-
- }
- });
复制代码 |