如何为@Async方法使用自定义执行程序? [英] How can I use a custom executor for an @Async method?

查看:338
本文介绍了如何为@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.

那怎么称呼?

推荐答案

四个选项:

  1. 声明单个TaskExecutor
  2. 类型的bean
  3. 声明一个名称为AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME("taskExecutor")
  4. 的bean
  5. 实施
  6. 对于单个类/方法,请在
  1. Declare a single bean of type TaskExecutor
  2. Declare a single bean with the name AsyncExecutionAspectSupport.DEFAULT_TASK_EXECUTOR_BEAN_NAME ("taskExecutor")
  3. Implement AsyncConfigurer#getAsyncExecutor
  4. For individual classes/methods, provide a qualifier of an executor bean in the @Async#value.

这篇关于如何为@Async方法使用自定义执行程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆