简体   繁体   中英

how to create multiple threads pools for one method in spring boot using @Async

I have a method but want to create multiple thread pools. currently i am writing under way

@Async ("poolProcessor1")
method A1 () {
// Handle similar logic A2
}


@Async ("poolProcessor2")
method A2 () {
// Handle similar logic A1

}

Is there a way I can create multiple thread pools on the same method? Can you please help me with suggestions or keywords. I use Java spring boot

You can use thread pool without method level Async annotation (illustrated below). You can programmatically decide which thread pool to use for different logics.

@Autowired
private Executor poolProcessor1;

@Autowired
private Executor poolProcessor2;

method A1 () {
  poolProcessor1.execute(()->...execute come logic or method)
  poolProcessor2.execute(()->...execute come logic or method)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM