spring - Spring-Boot @Async:如何在运行时使用@Async 找出实际的方法名称注释?
问题描述
我需要找出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;
}
如果您有更好的建议来找出正在执行的实际方法,请告诉我。我需要为审计/计量学目的收集方法名称。
解决方案
推荐阅读
- scala - SFTP上传文件成功但无法终止
- c# - 如何通过非泛型类函数传递泛型类型
- vue.js - Quasar Framework 如何存储登录哈希,以便它在 Web 和移动(使用 cordova)应用程序上工作
- javascript - 如何捕获失败的 WebSocket 消息?
- android - ARCore 记录/回放系统
- c++ - 明确论证?
- html - fontawesome有问题,它没有出现
- javascript - 在 ASP.NET Razor 视图中对大量对象进行分页
- symfony - Symfony 5 pb 与存储库
- javascript - 数组和 JSON 之间是否存在混合数据结构?