instanceOfObject instanceOfObject - 9 months ago 191
Java Question

Multiple spring task executors with annotation-driven spring tasks

I have a class

being called by another method in another class (i.e. Caller).

public class Caller {
public void poll(){
//do stuff


public class MessageProcessor{

public void process(String msg){
//do stuff here.


Spring file looks like:

<task:executor id="abcExecutor" pool-size="9" rejection-policy-"CALLER_RUNS"/>

I want to add another @Async executor:

public void remove(String msg){
//do stuff here.

public void kill(){
//do stuff

By adding another executor in spring file:

<task:executor id="defExecutor" pool-size="9" rejection-policy="CALLER_RUNS"/>

But how to add multiple executors in
<task:annotation-driven executor="abcExecutor" scheduler="scheduler" mode="proxy" proxy-target-class="true"/>

How can I make these multiple executors run with annotation?

PS: Obviously, I don't want to have the same pool being used for both the


The @Async("defExecutor") is sufficient to designate the method to be handled by the 2nd executor. The xml declaration specifies only the default executor, which will be used whenever no value is specified in @Async.

See the explanation of Chris Beams in this issue: