1 //使用newFixedThreadPool创建线程 2 ExecutorService fixedPool = Executors.newFixedThreadPool(5); 3 for (int i = 0; i <20; i++) { 4 fixedPool.execute(new MyThread03(i)); 5 try { 6 Thread.sleep(1000); 7 } catch (InterruptedException e) { 8 // TODO Auto-generated catch block 9 e.printStackTrace(); 10 } 11 } 12 } 13 } 14 class MyThread03 implements Runnable{ 15 int num; 16 17 public MyThread03(int num) { 18 super(); 19 this.num = num; 20 } 21 22 @Override 23 public void run() { 24 System.out.println(Thread.currentThread().getName()+":"+num); 25 26 }