本文主要是介绍ThreadPoolExecutor的四种抛弃策略,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
常规情况下:
ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 3, 1, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(5), new ThreadPoolExecutor.AbortPolicy());//任务8,9没执行,不继续执行,抛出异常
/* Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@4b6995df rejected from java.util.concurrent.ThreadPoolExecutor@61443d8f[Running, pool size = 3, active threads = 3, queued tasks = 5, completed tasks = 0]at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)pool-1-thread-1
这篇关于ThreadPoolExecutor的四种抛弃策略的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!