如何为@Async方法使用自定义执行程序? [英] How can I use a custom executor for an @Async method?
本文介绍了如何为@Async方法使用自定义执行程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用ThreadPoolExecutor
作为带有@ASync
批注的自定义执行程序.
I am using ThreadPoolExecutor
as my custom executor with @ASync
annotation.
在google中,我发现以下任务需要在xml
中进行配置,但是我不确定myExecutor
如何映射到我的自定义执行程序.
In google, I have found that the task below needs to be configured in xml
but I'm not sure how the myExecutor
is mapped to my custom executor.
<task:annotation-driven executor="myExecutor" />
甚至发现在bean属性中,也没有给出其路径.
Even found that in bean properties, its path is not given.
那怎么称呼?
推荐答案
四个选项:
- 声明单个
TaskExecutor
类型的bean
- 声明一个名称为
AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME
("taskExecutor"
) 的bean
- 实施
- 对于单个类/方法,请在
- Declare a single bean of type
TaskExecutor
- Declare a single bean with the name
AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME
("taskExecutor"
) - Implement
AsyncConfigurer#getAsyncExecutor
- For individual classes/methods, provide a qualifier of an executor bean in the
@Async#value
.
这篇关于如何为@Async方法使用自定义执行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文