java 常用的线程池

public static void main(String[] args) {
ExecutorService threadPool
=Executors.newFixedThreadPool(2);


for(int i=0;i<5;i++){

Runnable runn =new Runnable(){

public void run(){
Thread t = Thread.currentThread();
System.out.println(t.getName());

System.out.println("");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {

e.printStackTrace();
}

}


};

threadPool.execute(runn);
System.out.println();

}
//shutdown()
threadPool.shutdownNow();

}

猜你喜欢

转载自www.cnblogs.com/fyfday01/p/9059714.html