I'm using spring annotations for configuring Controllers(@EnableWebMvc), services(@service and @ComponentScan). In one of my services I have a method annotated with @Async and I also have @EnableAsync added on my config class. When one of MVC controller calls the service method which is annotated with @Async I expect the controller to return immediately without waiting for the service method to complete. By it does not. When I setup the break point in the service method I see that it is in fact running in a seperate thread i.e. the stacktrace does show that it is using SimpleAsyncTaskExecutor as I configured below.
Here is the annotation in my configuration class looks like
@Configuration
@EnableWebMvc
@EnableScheduling
@ComponentScan(basePackages = "com.mypackage")
@EnableAsync
public class WebApplicationConfig extends WebMvcConfigurerAdapter implements AsyncConfigurer {
...
...
@Override
public Executor getAsyncExecutor() {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor("SimpleExecutor-");
executor.setConcurrencyLimit(props.getIntegerProperty(SysProps.EMAIL_SENDER_CONCURRENT_THREAD_LIMIT));
return executor;
}
And here is my MVC controller method looks like
@Autowired
private EmailService emailService;
@ResponseStatus(value = HttpStatus.CREATED)
@RequestMapping(value = "/asset/{assetId}/slideshare/email", method = RequestMethod.POST, produces = JSON_UTF8)
@ResponseBody
@ApiResponseObject
public Link createAndEmailSlideShareLink(@PathVariable final String assetId,
@RequestParam(value = "email") final String email,
@RequestParam(value = "message", required = false) final String message,
final HttpServletRequest request) {
Link link = linkService.createLink()
emailService.sendSlideShareAssetEmail(user,link...
return link;
}
And the service method looks like this
@Async
public void sendSlideShareAssetEmail(User user, String email, String msg, String link, Asset asset) {
Why doesn't the MVC controller does not return immediately?