【定义线程池报错】BeanInstantiationException: Failed to instantiate [java.util.concurrent.Executor]

[定义线程池bug修复]
(BeanInstantiationException: Failed to instantiate [java.util.concurrent.Executor]: Factory method ‘generateExchangeCodeExector’ threw exception)

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.concurrent.Executor]: Factory method ‘generateExchangeCodeExector’ threw exception; nested exception is java.lang.ClassCastException: class org.apache.tomcat.util.threads.ThreadPoolExecutor C a l l e r R u n s P o l i c y c a n n o t b e c a s t t o c l a s s j a v a . u t i l . c o n c u r r e n t . R e j e c t e d E x e c u t i o n H a n d l e r ( o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T h r e a d P o o l E x e c u t o r CallerRunsPolicy cannot be cast to class java.util.concurrent.RejectedExecutionHandler (org.apache.tomcat.util.threads.ThreadPoolExecutor CallerRunsPolicycannotbecasttoclassjava.util.concurrent.RejectedExecutionHandler(org.apache.tomcat.util.threads.ThreadPoolExecutorCallerRunsPolicy is in unnamed module of loader ‘app’; java.util.concurrent.RejectedExecutionHandler is in module java.base of loader ‘bootstrap’)

报错翻译:
根据异常信息,生成 ExchangeCodeExecutor 的工厂方法(factory method)generateExchangeCodeExector 抛出了异常,并把原因嵌套在 BeanInstantiationException 中。
具体异常信息是 java.lang.ClassCastException: class org.apache.tomcat.util.threads.ThreadPoolExecutor C a l l e r R u n s P o l i c y c a n n o t b e c a s t t o c l a s s j a v a . u t i l . c o n c u r r e n t . R e j e c t e d E x e c u t i o n H a n d l e r 。这是因为 o r g . a p a c h e . t o m c a t . u t i l . t h r e a d s . T h r e a d P o o l E x e c u t o r CallerRunsPolicy cannot be cast to class java.util.concurrent.RejectedExecutionHandler。这是因为 org.apache.tomcat.util.threads.ThreadPoolExecutor CallerRunsPolicycannotbecasttoclassjava.util.concurrent.RejectedExecutionHandler。这是因为org.apache.tomcat.util.threads.ThreadPoolExecutorCallerRunsPolicy 类型不能被强制转换成 java.util.concurrent.RejectedExecutionHandler 类型。产生该异常的情况一般是因为 Java 运行时环境中存在多个版本的相同类或者接口,而在运行时选择的版本与编译时使用的版本不一致,从而导致类型转换错误。

**解决方案:**引入的包不一致,拒绝策略处理和线程池引入的包应该是一致才不会报错,因为运行和编译的环境不一致了,请再次检查一下引入的包是否是这样的:
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值