???????????????У???????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????Ч??????????????????????????????
?????????????????????????????????????????????????????????????????????????????
??????Java?п????????????????????Ч????????????????????Java????????????????????ThreadPoolExecutor???е?????????????????????????????????????????????????????????????κ?????????????С??
????????????????????
?????.Java?е?ThreadPoolExecutor??
??????.??????????????????
??????.??????
??????.??κ?????????????С??

???????в???????????????????????????
?????.Java?е?ThreadPoolExecutor??
????java.uitl.concurrent.ThreadPoolExecutor?????????к????????????????????????Java?е???????????????????????????????????ThreadPoolExecutor????????????
??????ThreadPoolExecutor???????????????????
????public class ThreadPoolExecutor extends AbstractExecutorService {
????.....
????public ThreadPoolExecutor(int corePoolSize??int maximumPoolSize??long keepAliveTime??TimeUnit unit??
????BlockingQueue<Runnable> workQueue);
????public ThreadPoolExecutor(int corePoolSize??int maximumPoolSize??long keepAliveTime??TimeUnit unit??
????BlockingQueue<Runnable> workQueue??ThreadFactory threadFactory);
????public ThreadPoolExecutor(int corePoolSize??int maximumPoolSize??long keepAliveTime??TimeUnit unit??
????BlockingQueue<Runnable> workQueue??RejectedExecutionHandler handler);
????public ThreadPoolExecutor(int corePoolSize??int maximumPoolSize??long keepAliveTime??TimeUnit unit??
????BlockingQueue<Runnable> workQueue??ThreadFactory threadFactory??RejectedExecutionHandler handler);
????...
????}
?????????????????????ThreadPoolExecutor?????AbstractExecutorService??????????????????????????????????????????????????????????????????????????????????????????е???????????
???????????????1??????и???????????壺
????corePoolSize?????????С??????????????潲????????????????з????????????????????????????£??????в?????κ????????????????????????????????????????????prestartAllCoreThreads()????prestartCoreThread()??????????2???????????????????????????????????????????????????????corePoolSize??????????????????????£??????????????????е???????0????????????????????????????????????????е?????????corePoolSize?????????????????????е??У?
????maximumPoolSize????????????????????????????????????????????????????ж???????????????
????keepAliveTime?????????????????????????????????????????£???е??????е??????????corePoolSize???keepAliveTime??????????????????е????????????corePoolSize???????????е??????????corePoolSize??????????????е?????keepAliveTime??????????????????е????????????corePoolSize???????????????allowCoreThreadTimeOut(boolean)?????????????е????????????corePoolSize???keepAliveTime??????????????????????е???????0??
????unit??????keepAliveTime?????λ????7????????TimeUnit??????7?????????
????TimeUnit.DAYS;               //??
????TimeUnit.HOURS;             //С?
????TimeUnit.MINUTES;           //????
????TimeUnit.SECONDS;           //??
????TimeUnit.MILLISECONDS;      //????
????TimeUnit.MICROSECONDS;      //???
????TimeUnit.NANOSECONDS;       //????
????workQueue????????????У??????洢?????е????????????????????????????????????й?????????????????????????????????????????????
????ArrayBlockingQueue;
????LinkedBlockingQueue;
????SynchronousQueue;
????ArrayBlockingQueue??PriorityBlockingQueue??y??????????LinkedBlockingQueue??Synchronous???????????????BlockingQueue?й??
????threadFactory?????????????????????????
????handler???????????????????????????????????????
????ThreadPoolExecutor.AbortPolicy:???????????RejectedExecutionException????
????ThreadPoolExecutor.DiscardPolicy????????????????????????
????ThreadPoolExecutor.DiscardOldestPolicy????????????????????????3???????????????????
????ThreadPoolExecutor.CallerRunsPolicy??????????????????
????????????????????????????????????????
???????????????ThreadPoolExecutor??????????????ThreadPoolExecutor?????AbstractExecutorService?????????????AbstractExecutorService??????
????public abstract class AbstractExecutorService implements ExecutorService {
????protected <T> RunnableFuture<T> newTaskFor(Runnable runnable?? T value) { };
????protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { };
????public Future<?> submit(Runnable task) {};
????public <T> Future<T> submit(Runnable task?? T result) { };
????public <T> Future<T> submit(Callable<T> task) { };
????private <T> T doInvokeAny(Collection<? extends Callable<T>> tasks??
????boolean timed?? long nanos)
????throws InterruptedException?? ExecutionException?? TimeoutException {
????};
????public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
????throws InterruptedException?? ExecutionException {
????};
????public <T> T invokeAny(Collection<? extends Callable<T>> tasks??
????long timeout?? TimeUnit unit)
????throws InterruptedException?? ExecutionException?? TimeoutException {
????};
????public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
????throws InterruptedException {
????};
????public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks??
????long timeout?? TimeUnit unit)
????throws InterruptedException {
????};
????}
????AbstractExecutorService??????????????????ExecutorService?????
????????????ExecutorService????????
????public interface ExecutorService extends Executor {
????void shutdown();
????boolean isShutdown();
????boolean isTerminated();
????boolean awaitTermination(long timeout?? TimeUnit unit)
????throws InterruptedException;
????<T> Future<T> submit(Callable<T> task);
????<T> Future<T> submit(Runnable task?? T result);
????Future<?> submit(Runnable task);
????<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
????throws InterruptedException;
????<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks??
????long timeout?? TimeUnit unit)
????throws InterruptedException;
????<T> T invokeAny(Collection<? extends Callable<T>> tasks)
????throws InterruptedException?? ExecutionException;
????<T> T invokeAny(Collection<? extends Callable<T>> tasks??
????long timeout?? TimeUnit unit)
????throws InterruptedException?? ExecutionException?? TimeoutException;
????}
??????ExecutorService????????Executor????????????Executor????????
????public interface Executor {
????void execute(Runnable command);
????}
??????????????????????ThreadPoolExecutor??AbstractExecutorService??ExecutorService??Executor?????????????
????Executor??????????????????????????????????execute(Runnable)????????void???????Runnable?????????????????????????????д????????????
???????ExecutorService???????Executor?????????????Щ??????submit??invokeAll??invokeAny???shutDown???
??????????AbstractExecutorService?????ExecutorService?????????????ExecutorService???????????з?????
???????ThreadPoolExecutor???????AbstractExecutorService??
??????ThreadPoolExecutor?????м????????????????
????execute()
????submit()
????shutdown()
????shutdownNow()
????execute()???????????Executor???????????????ThreadPoolExecutor???????????????????????ThreadPoolExecutor??????????????????????????????????????????????????С?
????submit()????????ExecutorService???????????????AbstractExecutorService?????????????????ThreadPoolExecutor?в???ж????????д??????????????????????????????????????execute()????????????????????????е????????submit()????????????????????????????execute()???????????????????Future???????????н????Future??????????????????????
????shutdown()??shutdownNow()???????????????
???????к?????????????
???????磺getQueue() ??getPoolSize() ??getActiveCount()??getCompletedTaskCount()????????????????????????????????????????в???API??