Suppose a new task is submitted in method execute(),why create a new thread instead of using an existing thread when the number of threads are less than corePoolSize?
public static void main(String[] args) {
ThreadPoolExecutor service = new ThreadPoolExecutor(2, 5, 10L,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(3),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy());
try {
for (int i = 0; i < 8; i++) {
service.execute(() -> {
System.out.println(Thread.currentThread().getName());
});
}
} finally {
service.shutdown();
}
}
I got this question on the Internet. Is it correct? And tell me the reason please.