当当前线程池只有 核心线程1(空闲)和 非核心线程2(忙碌),过了空闲时间后,核心线程1是否会关闭?也就是非核心线程2变为核心线程
package com.yang.demo;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ThreadPoolDemo {
public static void main(String[] args) throws InterruptedException {
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 2,
1, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(1));
// 第一个任务:开启核心线程1
threadPool.execute(() -> {
System.out.println(System.currentTimeMillis() + Thread.currentThread().getName() + "开启");
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
// 第二个任务:填满阻塞队列
threadPool.exec