Created
May 11, 2017 21:43
-
-
Save khoubyari/121ae53fa83e23c0424938290cf5483f to your computer and use it in GitHub Desktop.
How to configure the Async executor in Spring Boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reference: http://www.baeldung.com/spring-async , http://javasampleapproach.com/java-integration/start-spring-async-spring-boot | |
... | |
//in ExecutorConfig.java | |
@Configuration | |
@EnableAsync | |
public class AsyncConfiguration { | |
@Bean(name = "myAsyncExecutor") | |
public Executor asyncExecutor() { | |
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | |
executor.setCorePoolSize(10); | |
executor.setQueueCapacity(10); | |
executor.setMaxPoolSize(50); | |
executor.setThreadNamePrefix("my-async-executor-"); | |
executor.initialize(); | |
return executor; | |
} | |
} | |
// then in the consumer bean | |
@Async("myAsyncExecutor") | |
@Transactional(isolation = Isolation.READ_COMMITTED, rollbackFor={Throwable.class}, propagation = Propagation.REQUIRES_NEW) | |
public void myAsyncMethod() { | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the relation between myAsyncExecutor and myAsyncMethod