package ThreadDemo;
import java.lang.reflect.Executable;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
// 线程池
public class Test27_Pool {
public static void main(String[] args) {
// 1. 创建服务->创建线程池
// nThreads:线程池的大小; //Executor:执行器
ExecutorService service= Executors.newFixedThreadPool(10);
// 2. 通过线程池,执行线程
service.execute(new Thread(new PoolDemo(),"a"));
service.execute(new Thread(new PoolDemo(),"b"));
service.execute(new Thread(new PoolDemo(),"c"));
service.execute(new Thread(new PoolDemo(),"d"));
// 3. 关闭
service.shutdown();
}
}
class PoolDemo implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
标签:27,java,service,Thread,PoolDemo,线程,new
From: https://www.cnblogs.com/zhanjianhai/p/17688499.html