Executors
詳解【待完善】* Factory and utility methods for {@link Executor}, {@link * ExecutorService}, {@link ScheduledExecutorService}, {@link * ThreadFactory}, and {@link Callable} classes defined in this * package. This class supports the following kinds of methods:
針對定義在這個包中的 Executor,ExecutorService,ScheduledExecutorService ,ThreadFactory,Callable
等類的工廠/實用方法。這個類支持以下幾種方法:java
Methods that create and return an {@link ExecutorService} set up with commonly useful configuration settings. 使用經常使用且有用的配置去建立並返回一個 ExecutorService
。app
Methods that create and return a {@link ScheduledExecutorService} set up with commonly useful configuration settings. 使用經常使用配置返回一個 ScheduledExecutorService
ide
Methods that create and return a 「wrapped」 ExecutorService, that disables reconfiguration by making implementation-specific methods inaccessible. 建立並返回一個"wrapped"
ExecutorService
,這使重配置無效,經過實現具體的,不可訪問的方法。ui
Methods that create and return a {@link ThreadFactory} that sets newly created threads to a known state. 建立並返回一個ThreadFactory,這個能夠設置最近建立的線程到一個指定的狀態。this
Methods that create and return a {@link Callable} out of other closure-like forms, so they can be used in execution methods requiring {@code Callable}.線程
newFixedThreadPool
/** * Creates a thread pool that reuses a fixed number of threads * operating off a shared unbounded queue. At any point, at most * {@code nThreads} threads will be active processing tasks. * If additional tasks are submitted when all threads are active, * they will wait in the queue until a thread is available. * If any thread terminates due to a failure during execution * prior to shutdown, a new one will take its place if needed to * execute subsequent tasks. The threads in the pool will exist * until it is explicitly {@link ExecutorService#shutdown shutdown}. * * @param nThreads the number of threads in the pool * @return the newly created thread pool * @throws IllegalArgumentException if {@code nThreads <= 0} */ public static ExecutorService newFixedThreadPool(int nThreads) { return new ThreadPoolExecutor(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); }
該方法的功能就是:建立一個線程池,可用於複用一個固定數量的線程,操做一個共享的很大的(任務)隊列。code