MyThread 写道
package com.honzh.mwq.test;
import java.io.IOException;
public class MyThread implements Runnable {
private int i;
public MyThread(int i) {
this.i = i;
}
public void run() {
try {
FileOutUtil.out(Thread.currentThread().getName() + " " + this.i + " 正在执行...");
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) { ExecutorService pool = Executors.newFixedThreadPool(2); for (int i = 0 ; i < 100000000; i++) { pool.execute(new MyThread(i)); } pool.shutdown(); try { FileOutUtil.out("pool is shutdown"); } catch (IOException e) { e.printStackTrace(); } }
public static void main(String[] args) { ExecutorService pool = Executors.newCachedThreadPool(); for (int i = 0 ; i < 1000000000; i++) { pool.execute(new MyThread(i)); } pool.shutdown(); try { FileOutUtil.out("pool is shutdown"); } catch (IOException e) { e.printStackTrace(); } }