我需要找出TaskDecorator 中的@Async 方法名称。如何从 TaskDecorator 中找出方法名称(asyncMethodWithReturnType),或者我有更好的方法来找出在 Spring Boot 2 中用 @Async 注释的实际方法?
@Bean(name = "threadPoolTaskExecutor")
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor th = new ThreadPoolTaskExecutor();
// HERE AUDIT WOULD collect metric about method name.
th.setTaskDecorator(runnable -> AuditWrapper.auditWrapper(runnable))
}
@Async
public Future<String> asyncMethodWithReturnType() {
System.out.println("Execute method asynchronously - "
+ Thread.currentThread().getName());
try {
Thread.sleep(5000);
return new AsyncResult<String>("hello world !!!!");
} catch (InterruptedException e) {
//
}
return null;
}
如果您有更好的建议来找出正在执行的实际方法,请告诉我。我需要为审计/计量学目的收集方法名称。