???????Java?????
???????????? ???????[ 2016/4/7 10:38:14 ] ??????????????????? ???????
???????????????校???????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????效??????????????????????????????
?????????????????????????????????????????????????????????????????????????????
??????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??
??????

???路???
??????????????????
2023/3/23 14:23:39???写?貌??????????
2023/3/22 16:17:39????????????????????些??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???路???????路
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11