Size:執行緒池大小在最小值 corePoolSize 與最大值 maximumPoolSize 之間動態調整,可透過 getPoolSize() 取得當前大小。
Queue:用於存放等待執行的任務。
ThreadPoolExecutor tpe = new ThreadPoolExecutor(
M, N, TIMEOUT, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()
);
Task[] tasks = new Task[nTasks];
for (int i = 0; i < nTasks; i++) {
tasks[i] = new Task(n, "Task " + i);
tpe.execute(tasks[i]);
}
tpe.shutdown();
prestartAllCoreThreads() 或 prestartCoreThread() 預先建立)。