- ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
- //ExecutorService pool = Executors.newSingleThreadExecutor();
- pool.execute(new Runnable()
- {
- public void run() {
- for(int i=0;i<1000;i++)
- {
- try {
- Thread.sleep((new Random().nextInt(10)+1)*1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- vehicles.add(Road.this.name+"..."+i);
- }
- }
-
- });
复制代码 一个是产生线程池里放一个线程,另一个是产生单个线程,这样理解对不对?
|