如何在 Spring @Async 方法中获取任务?因为我想返回 FutureTask,但是 futureTask 的构造函数需要传递 Runnable 或 Callable 参数。
前
@Component
public class ConversionProcessor {
@Async
public Future<String> convert() {
//doing something
return new AsyncResult<>("Hello");
}
}
预期的
@Component
public class ConversionProcessor {
@Async
public FutureTask convert() {
//doing something
return new FutureTask();
// compiler error, 'cannot resolve constructor FutureTask()'
}
}