有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Spring调度器/执行器的java AOP特性

我一直在处理一个旧项目,其中启用了Spring调度程序(正在使用@Scheduled),也启用了一些本地JDK线程池实例。在下面我看到的项目配置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"/>

一些quartz实现产生于它自己的作业定义,触发器定义,其中作业定义了它们自己的threadpoolexecutor,如下所示

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

然后开始将任务(可运行项)提交到池中

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

但我看到的是,在某个时刻,针对这些任务抛出了Spring任务拒绝异常。这是胡说八道(除非Spring使用AOP拦截线程池执行器,即使它们是本机创建的)。因为没有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

那么问题又来了,spring调度器和执行器(如果配置)是否在应用程序中拦截ThreadPoolExecutors


共 (1) 个答案

  1. # 1 楼答案

    问题出在我最初的设想上。随着spring调试的深入,我看到队列任务提交来自另一个bean。它有异步任务注册,应用程序中的每个错误都会调用这个异步方法来触发一些自定义操作。因此,一旦一个端点发生了严重的故障,无法恢复,就会出现这个问题。因为当前的设计一直在调用异步方法,每次调用都会占用执行器池中的一个插槽