newScheduledThreadPool() 方法的参数 "corePoolSize" 是什么意思?
What does it means "corePoolSize", param of newScheduledThreadPool() method?
我不清楚 class java.util.concurrent.Executors.
中 newScheduledThreadPool() 方法的 "corePoolSize" 参数是什么意思
如果我输入较高的数值会怎样,如果我输入较小的数值会怎样?
// corePoolSize = 1;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
或
// corePoolSize = 5;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
定义该值的正确方法是什么?
在ThreadPoolExecutor的javadoc中有详细解释-摘录:
When a new task is submitted in method execute(Runnable)
, and fewer than corePoolSize
threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more than corePoolSize
but less than maximumPoolSize
threads running, a new thread will be created only if the queue is full.
因此它定义了是否应根据执行程序的状态创建线程。
在 ScheduledExecutorService
的情况下,如果您不打算在给定时间内完成一项以上的任务 运行,则 corePoolSize
为 1 可能效率更高.如果需要,它不会阻止创建更多线程。
我不清楚 class java.util.concurrent.Executors.
中 newScheduledThreadPool() 方法的 "corePoolSize" 参数是什么意思如果我输入较高的数值会怎样,如果我输入较小的数值会怎样?
// corePoolSize = 1;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
或
// corePoolSize = 5;
java.util.concurrent.Executors.newScheduledThreadPool(corePoolSize);
定义该值的正确方法是什么?
在ThreadPoolExecutor的javadoc中有详细解释-摘录:
When a new task is submitted in method
execute(Runnable)
, and fewer thancorePoolSize
threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more thancorePoolSize
but less thanmaximumPoolSize
threads running, a new thread will be created only if the queue is full.
因此它定义了是否应根据执行程序的状态创建线程。
在 ScheduledExecutorService
的情况下,如果您不打算在给定时间内完成一项以上的任务 运行,则 corePoolSize
为 1 可能效率更高.如果需要,它不会阻止创建更多线程。