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