具有注释驱动的弹簧任务的多个弹簧任务执行器

ins*_*ect 8 java spring scheduled-tasks spring-annotations

我有一个类MessageProcessor被另一个类中的另一个方法调用(即调用者).

public class Caller {
@Scheduled(filxedDelay=10)
public void poll(){
//do stuff
messageProcessor.process(msg);
}

}

public class MessageProcessor{

@Async(value="abcExecutor")
public void process(String msg){
//do stuff here.
}

}
Run Code Online (Sandbox Code Playgroud)

Spring文件看起来像:

<task:executor id="abcExecutor" pool-size="9" rejection-policy-"CALLER_RUNS"/>
Run Code Online (Sandbox Code Playgroud)

我想添加另一个@Async执行程序:

 @Async(value="defExecutor")
    public void remove(String msg){
    //do stuff here.
    }

@Scheduled(filxedDelay=10)
public void kill(){
//do stuff
messageProcessor.remove(msg);
}
Run Code Online (Sandbox Code Playgroud)

通过在spring文件中添加另一个执行程序:

<task:executor id="defExecutor" pool-size="9" rejection-policy="CALLER_RUNS"/>
Run Code Online (Sandbox Code Playgroud)

但是如何在中添加多个执行程序 <task:annotation-driven executor="abcExecutor" scheduler="scheduler" mode="proxy" proxy-target-class="true"/>

如何使用注释运行这些多个执行程序?

PS:显然,我不希望这两种@Async方法都使用相同的池

Boz*_*zho 12

所述@Async("defExecutor")足以以指定要由所述第二执行器能够处理的方法.xml声明仅指定默认执行程序,只要未指定任何值,就会使用该执行程序@Async.

克里斯梁的解释这个问题: