Watch the video of the learning process: [Crazy God Speaks Java]
https://www.bilibili.com/video/BV1V4411p7EF?p=3
Welcome everyone to support Oh, very conscientious teacher!
java code example:
package com.zjl;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by zjl
* 2020/11/19
**/
public class TestPool {
public static void main(String[] args) {
//创建线程,创建线程池
//newFixedThreadPool 参数为线程池大小
ExecutorService executorService = Executors.newFixedThreadPool(10);
//执行
executorService.execute(new MyThread());
executorService.execute(new MyThread());
executorService.execute(new MyThread());
executorService.execute(new MyThread());
//关闭连接
executorService.shutdown();
}
}
class MyThread implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}