简体   繁体   English

Spring Scheduler/Executor 的 AOP 特性

[英]AOP features of Spring Scheduler/Executor

I have been working on an old project where both Spring scheduler is enabled (@Scheduled actively being used) also some native JDK thread pool instances active too.我一直在开发一个旧项目,其中启用了 Spring 调度程序(积极使用 @Scheduled),也启用了一些本机 JDK 线程池实例。 In the project configuration xml I see below;在我在下面看到的项目配置 xml 中;

<task:scheduler id="taskScheduler" pool-size="${task-scheduler.pool-size}"/>
<task:executor id="taskExecutor" pool-size="${task-executor.pool-size}" queue-capacity="${task-executor.queue-capacity}"/>
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler"/>

And them some quartz implementation comes arise with its own job definition, trigger definition stuff where the Jobs defines their own ThreadPoolExecutors as below,并且他们的一些石英实现出现了它自己的作业定义,触发器定义的东西,其中作业定义了自己的 ThreadPoolExecutors,如下所示,

BlockingQueue<Runnable> workerTaskQueue = new ArrayBlockingQueue<Runnable>(poolSize*3);
 threadPoolExecutor = new 
     ThreadPoolExecutor(poolSize,poolSize,1000L,TimeUnit.MILLISECONDS,workerTaskQueue);

then starts to submit tasks (Runnables) into the pool.然后开始将任务(Runnables)提交到池中。

threadPoolExecutor.execute(new ImcpWorker(task, this, workerTaskUtil));

But what I see is that at some point the Spring task rejection exception thrown for these tasks.但我看到的是,在某些时候为这些任务抛出的 Spring 任务拒绝异常。 This is nonsense (unless Spring intercepts using AOP the thread pool executors, even if they are created natively).这是无稽之谈(除非 Spring 使用 AOP 拦截线程池执行程序,即使它们是本机创建的)。 Because there is no spring managed executor.因为没有 spring 管理的执行器。

2021-06-21 11:51:58,679 ERROR [pool-151-thread-81] LisJobHandler - Exception occured: Executor [java.util.concurrent.ThreadPoolExecutor@5532827b[Running, pool size = 1000, active threads = 1000, queued tasks = 100000, completed tasks = 135592411]] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@5a237108 msisdn:5363443640 org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@5532827b[Running, pool size = 1000, active threads = 1000, queued tasks = 100000, completed tasks = 135592411]] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@5a237108 2021-06-21 11:51:58,679 错误 [pool-151-thread-81] LisJobHandler - 发生异常:执行程序 [java.util.concurrent.ThreadPoolExecutor@5532827b[正在运行,池大小 = 1000,活动线程 = 1000 排队任务 = 100000,完成的任务 = 135592411]] 没有接受任务:org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@5a237108 msisdn:5363443640 org.springframework.core.task.TaskRejectedException@util.Executor.java 5532827b[正在运行,池大小 = 1000,活动线程 = 1000,排队任务 = 100000,已完成任务 = 135592411]] 没有接受任务:org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@5a237108

So again the question, does spring scheduler and executors (if configured) intercepts ThreadPoolExecutors in an application ?那么问题又来了,spring 调度程序和执行程序(如果已配置)是否会拦截应用程序中的 ThreadPoolExecutors ?

Well the issue was out of nowhere about my initial assumption.好吧,问题出在我最初的假设上。 As I go deeper in spring debugging I see that the queue task submission comes from one of my other bean.当我深入了解 spring 调试时,我看到队列任务提交来自我的另一个 bean。 It has async task registrations and each error in the app calls this async method to trigger some custom actions.它有异步任务注册,应用程序中的每个错误都会调用这个异步方法来触发一些自定义操作。 So that once an endpoing failed really bad and can not recover, this issue occurs.因此,一旦端点失败且无法恢复,就会出现此问题。 Because the current design keeps calling the async method and each call occupies a slot in the executor's pool.因为当前的设计一直在调用 async 方法,并且每次调用都会占用执行器池中的一个槽。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM