23.线程池
package com.wen.thread;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @Author WangEn
* @CreateTime: 2021-05-04-20-17
* @Emile: wen_5988@163.com
*/
public class Test线程池 {
public static void main(String[] args) {
// 创建服务创建线程池,用runnable下的
// callable 在TestCallable下面
// Executors.newFixedThreadPool(10); 表示创建容量为10的线程池
ExecutorService service = Executors.newFixedThreadPool(10);
MyThread myThread = new MyThread();
service.execute(myThread);
service.execute(myThread);
service.execute(myThread);
service.execute(myThread);
service.execute(myThread);
service.execute(myThread);
service.shutdown();
}
}
class MyThread implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}