线程池基本使用
作者:互联网
线程池基本使用
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class PoolDemo {
public static void main(String[] args) {
// 创建一个长度为5的固定线程池
ExecutorService executorService = Executors.newFixedThreadPool(5);
// 执行
executorService.execute(new MyThread());
executorService.execute(new MyThread());
executorService.execute(new MyThread());
executorService.execute(new MyThread());
// 关闭连接
executorService.shutdown();
}
}
// Runnable接口实现类
class MyThread implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
标签:基本,execute,MyThread,线程,使用,new,executorService,public 来源: https://www.cnblogs.com/coderDreams/p/15915578.html