如何在Spring @Async方法中获取任务

时间:2018-08-28 14:14:01

标签: java asynchronous spring-async

如何在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()'
    }
}

0 个答案:

没有答案