I have a scenario in my springboot application, where I submit tasks into a threadpool for async execution.Now some of the methods inside child execution is part of aspect point advice with @AfterReturn. I observe that even if processing is done asnyc, my main thread keeps executing the point cut advice from child thread and my service does not return a value until, all child thread finished execution. Any pointer how to make the advice run on the executing thread itself? So in short, controller method does not return response until dao method execution and its corresponding point cut is executed.
@Controller
@RequestMapping(value = "/api")
public class SampleController {
@Autowired
SampleService service;
@RequestMapping(value = "/action", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String action(@RequestBody String request){
service.action(request);
return "Success";
}
}
@Service
public class SampleService{
@Autowired
SampleDao dao;
@Async("threadPoolExecutor")
public void action(String request){
dao.action(request);
}
}
@Repository
public class SampleDao{
public void action(String request){
//do some db things
}
}
@Aspect
@Component
public class SampleAspect{
@AfterReturning(
pointcut = "execution( * com.sample.*.*.SampleDao.action(..))",
returning = "result")
public void audit(JoinPoint joinPoint, Object result) {
//dosome thing
}
}