线程池
作者:互联网
线程池:就是管理线程的池子
测试创建
//测试线程池 public class TestPool { public static void main(String[] args) { //1.创建服务,创建线程池 //newFixedThreadPool 参数为:线程池的大小 ExecutorService service = Executors.newFixedThreadPool(10); //2.启动 service.execute(new MyThread()); service.execute(new MyThread()); service.execute(new MyThread()); service.execute(new MyThread()); service.execute(new MyThread()); //3.关闭连接 service.shutdown(); } } class MyThread implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread().getName()); } }
标签:execute,service,MyThread,线程,new,public 来源: https://www.cnblogs.com/hj98/p/16309184.html