pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok pool-1-thread-1 ok
pool-1-thread-3 ok pool-1-thread-2 ok pool-1-thread-1 ok pool-1-thread-2 ok pool-1-thread-3 ok pool-1-thread-2 ok pool-1-thread-1 ok pool-1-thread-2 ok pool-1-thread-3 ok pool-1-thread-1 ok
pool-1-thread-4 ok pool-1-thread-3 ok pool-1-thread-1 ok pool-1-thread-7 ok pool-1-thread-8 ok pool-1-thread-2 ok pool-1-thread-5 ok pool-1-thread-10 ok pool-1-thread-9 ok pool-1-thread-6 ok
pool-1-thread-2 ok pool-1-thread-1 ok pool-1-thread-2 ok pool-1-thread-1 ok pool-1-thread-2 ok
Process finished with exit code 0
i <=6 第三个线程开始执行
1 2 3 4 5 6 7 8
pool-1-thread-1 ok pool-1-thread-3 ok pool-1-thread-2 ok pool-1-thread-3 ok pool-1-thread-1 ok pool-1-thread-2 ok
Process finished with exit code 0
i <=8 五个线程都在执行
1 2 3 4 5 6 7 8 9 10
pool-1-thread-1 ok pool-1-thread-5 ok pool-1-thread-2 ok pool-1-thread-3 ok pool-1-thread-4 ok pool-1-thread-2 ok pool-1-thread-5 ok pool-1-thread-1 ok
pool-1-thread-1 ok pool-1-thread-5 ok pool-1-thread-1 ok pool-1-thread-4 ok pool-1-thread-3 ok pool-1-thread-2 ok pool-1-thread-1 ok pool-1-thread-5 ok java.util.concurrent.RejectedExecutionException: Task com.jokerdig.pool.Demo02$$Lambda$1/1831932724@7699a589 rejected from java.util.concurrent.ThreadPoolExecutor@58372a00[Running, poolsize=5, activethreads=3, queuedtasks=0, completedtasks=5] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379) at com.jokerdig.pool.Demo02.main(Demo02.java:30)
Process finished with exit code 0
CallerRunsPolicy() 哪来的去哪
1 2 3 4 5 6 7 8 9 10 11
pool-1-thread-1 ok pool-1-thread-4 ok main ok pool-1-thread-3 ok pool-1-thread-2 ok pool-1-thread-3 ok pool-1-thread-4 ok pool-1-thread-1 ok pool-1-thread-5 ok
Process finished with exit code 0
DiscardPolicy() 队列满了,丢掉任务,不会抛出异常
1 2 3 4 5 6 7 8 9 10
pool-1-thread-2 ok pool-1-thread-4 ok pool-1-thread-3 ok pool-1-thread-3 ok pool-1-thread-4 ok pool-1-thread-1 ok pool-1-thread-2 ok pool-1-thread-5 ok
Process finished with exit code 0
DiscardOldestPolicy() 队列满了,尝试和最早的竞争,不会抛出异常
1 2 3 4 5 6 7 8 9 10
pool-1-thread-2 ok pool-1-thread-5 ok pool-1-thread-4 ok pool-1-thread-3 ok pool-1-thread-1 ok pool-1-thread-5 ok pool-1-thread-4 ok pool-1-thread-2 ok