????5.??????????
?????????????????????????????????е?????????maximumPoolSize???????????????????????????????????????????????
????ThreadPoolExecutor.AbortPolicy:???????????RejectedExecutionException????
????ThreadPoolExecutor.DiscardPolicy????????????????????????
????ThreadPoolExecutor.DiscardOldestPolicy????????????????????????3???????????????????
????ThreadPoolExecutor.CallerRunsPolicy??????????????????
????6.???????
????ThreadPoolExecutor???????????????????????????????shutdown()??shutdownNow()?????У?
????shutdown()???????????????????????????????????????е??????????????????????????????μ?????
????shutdownNow()????????????????????????????е????????????????????У???????δ??е?????
????7.????????????????
????ThreadPoolExecutor????????????????????С???????setCorePoolSize()??setMaximumPoolSize()??
????setCorePoolSize?????ú?????С
????setMaximumPoolSize??????????????????????????С
????????????????С??????ThreadPoolExecutor??????????????????????????μ?????????????
??????.??????
???????????????????????????????????????????????????????????
????public class Test {
????public static void main(String[] args) {  
????ThreadPoolExecutor executor = new ThreadPoolExecutor(5?? 10?? 200?? TimeUnit.MILLISECONDS??
????new ArrayBlockingQueue<Runnable>(5));
????for(int i=0;i<15;i++){
????MyTask myTask = new MyTask(i);
????executor.execute(myTask);
????System.out.println("??????????????"+executor.getPoolSize()+"???????е????е??????????"+
????executor.getQueue().size()+"????????????????????"+executor.getCompletedTaskCount());
????}
????executor.shutdown();
????}
????}
????class MyTask implements Runnable {
????private int taskNum;
????public MyTask(int num) {
????this.taskNum = num;
????}
????@Override
????public void run() {
????System.out.println("???????task "+taskNum);
????try {
????Thread.currentThread().sleep(4000);
????} catch (InterruptedException e) {
????e.printStackTrace();
????}
????System.out.println("task "+taskNum+"??????");
????}
????}
??????н????
???????????task 0
??????????????????1???????е????е??????????0????????????????????0
??????????????????2???????е????е??????????0????????????????????0
???????????task 1
??????????????????3???????е????е??????????0????????????????????0
???????????task 2
??????????????????4???????е????е??????????0????????????????????0
???????????task 3
??????????????????5???????е????е??????????0????????????????????0
???????????task 4
??????????????????5???????е????е??????????1????????????????????0
??????????????????5???????е????е??????????2????????????????????0
??????????????????5???????е????е??????????3????????????????????0
??????????????????5???????е????е??????????4????????????????????0
??????????????????5???????е????е??????????5????????????????????0
??????????????????6???????е????е??????????5????????????????????0
???????????task 10
??????????????????7???????е????е??????????5????????????????????0
???????????task 11
??????????????????8???????е????е??????????5????????????????????0
???????????task 12
??????????????????9???????е????е??????????5????????????????????0
???????????task 13
??????????????????10???????е????е??????????5????????????????????0
???????????task 14
????task 3??????
????task 0??????
????task 2??????
????task 1??????
???????????task 8
???????????task 7
???????????task 6
???????????task 5
????task 4??????
????task 10??????
????task 11??????
????task 13??????
????task 12??????
???????????task 9
????task 14??????
????task 8??????
????task 5??????
????task 7??????
????task 6??????
????task 9??????
????????н??????????????????????????????5????????????????????????棬???????????????????????μ????????????????У???for????и?????20??????????????????????
??????????java doc?У?????????????????ThreadPoolExecutor?????????Executors?????????????????????????????
????Executors.newCachedThreadPool();        //????????????????????????С?Integer.MAX_VALUE
????Executors.newSingleThreadExecutor();   //?????????1??????
????Executors.newFixedThreadPool(int);    //?????????????С??????
????????????????????????????????
????public static ExecutorService newFixedThreadPool(int nThreads) {
????return new ThreadPoolExecutor(nThreads?? nThreads??
????0L?? TimeUnit.MILLISECONDS??
????new LinkedBlockingQueue<Runnable>());
????}
????public static ExecutorService newSingleThreadExecutor() {
????return new FinalizableDelegatedExecutorService
????(new ThreadPoolExecutor(1?? 1??
????0L?? TimeUnit.MILLISECONDS??
????new LinkedBlockingQueue<Runnable>()));
????}
????public static ExecutorService newCachedThreadPool() {
????return new ThreadPoolExecutor(0?? Integer.MAX_VALUE??
????60L?? TimeUnit.SECONDS??
????new SynchronousQueue<Runnable>());
????}
????????????????????????????????????????ThreadPoolExecutor??????????????????ú????
????newFixedThreadPool??????????corePoolSize??maximumPoolSize??????????????LinkedBlockingQueue??
????newSingleThreadExecutor??corePoolSize??maximumPoolSize???????1???????LinkedBlockingQueue??
????newCachedThreadPool??corePoolSize?????0????maximumPoolSize?????Integer.MAX_VALUE??????SynchronousQueue??????????????????????У????????г???60??????????
????????У????Executors?????????????????????????????????????????????????????????????ThreadPoolExecutor??????е??鷳?????????????????????????????????á?
???????????ThreadPoolExecutor?????????????????ThreadPoolExecutor???????д??