Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save khoubyari/121ae53fa83e23c0424938290cf5483f to your computer and use it in GitHub Desktop.

Select an option

Save khoubyari/121ae53fa83e23c0424938290cf5483f to your computer and use it in GitHub Desktop.
How to configure the Async executor in Spring Boot
// 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() {
}
@yaoyuanyy
Copy link
Copy Markdown

what is the relation between myAsyncExecutor and myAsyncMethod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment