首页 > 试题广场 >

import java.util.concurrent.Ar

[单选题]
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 15, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(5), new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
线程池executor在空闲状态下的线程个数是?
  • 0
  • 5
  • 10
  • 不确定
空闲状态下的非核心线程数呢?非核心线程不是15秒后才kill吗?
发表于 2019-02-11 23:38:06 回复(1)
public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5, 10, 15, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(5), new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
前三个参数:核心线程有5个,最大线程数是10个,keepAliveTime是15s,如果线程池中的线程大于5,那么超15s的空闲线程就会被结束,也就是说,一定会保持5个线程不会被结束。当所有任务完成后,会保持5个空闲的线程
发表于 2019-02-21 11:11:22 回复(1)
难道不应该选D吗?如果线程池在这之前一共只提交了两个任务,那么这两个任务执行完之后,线程池里不就只有两个线程吗???
发表于 2019-08-22 15:59:37 回复(0)