- <P>ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
- pool.execute(new Runnable()
- {
- public void run()
- {
- for(int i=0;i<5;i++)
- {
- long start = System.currentTimeMillis();
- try {
- Thread.sleep((int)(Math.random()*10+1)*1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- long end = System.currentTimeMillis();
- vehicles.add(RoadCollection.this.name+"_"+i+" spending time:"+(end-start)/1000);
- System.out.println(vehicles.get(i));
- }
- }
- });</P>
- <P> </P>
- <P> </P>
复制代码
|
|