现象
每天到业务高峰期就会出现提交线程被拒绝。
疑问点
什么原因会导致active threads远远小于poolsize的情况下,提交任务失败
关键信息
线程池配置
ExecutorService aService = new ThreadPoolExecutor(
130
, 300
, 60L
, TimeUnit.SECONDS
, new LinkedBlockingQueue<>(10)
, new ThreadFactoryBuilder().setNameFormat("aService-pool-%d").build()
, new ThreadPoolExecutor.AbortPolicy()
);
拒绝任务的日志信息
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.CompletableFuture$AsyncSupply@4e4dd145
rejected from java.util.concurrent.ThreadPoolExecutor@5c39c043[Running, pool size = 300, active threads = 4, queued tasks = 8, completed tasks = 3851427]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2065) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:833) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1365) ~[?:?]
at java.util.concurrent.CompletableFuture.asyncSupplyStage(CompletableFuture.java:1782) ~[?:?]
at java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:2005)
其他信息
- 这个线程池在使用时存在父子线程都使用的情况,这个用法本身有问题。
- 从监控来看,
java.util.concurrent.ThreadPoolExecutor#getActiveCount
指标最高到40;而java.util.concurrent.ThreadPoolExecutor#getPoolSize
指标已到高峰期就保持在300
解决方案
目前还有解决,待续
标签:java,记录,处理,util,concurrent,线程,CompletableFuture,ThreadPoolExecutor From: https://www.cnblogs.com/yansq0/p/17580498.html