???????????????校???????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????效??????????????????????????????
?????????????????????????????????????????????????????????????????????????????
??????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()???????????????
???????泻?????????????
???????纾篻etQueue() ??getPoolSize() ??getActiveCount()??getCompletedTaskCount()????????????????????????????????????????胁???API??