私の springboot アプリケーションには、非同期実行のためにタスクをスレッドプールに送信するシナリオがあります。現在、子実行内のメソッドの一部は、@AfterReturn を使用したアスペクト ポイント アドバイスの一部です。処理が asnyc で行われたとしても、メイン スレッドは子スレッドからのポイント カット アドバイスを実行し続け、サービスはすべての子スレッドが実行を終了するまで値を返さないことがわかりました。実行中のスレッド自体でアドバイスを実行する方法のポインタはありますか? つまり、dao メソッドの実行とそれに対応するポイント カットが実行されるまで、コントローラー メソッドは応答を返しません。
@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
}
}