[定义线程池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;