上QQ阅读APP看书,第一时间看更新
The @Asynchronous policy
Making an operation asynchronous is as simple as the following:
@Asynchronous
public Future<Connection> service() throws InterruptedException {
Connection conn = new Connection() {
{
Thread.sleep(1000);
}
@Override
public String getData() {
return "service DATA";
}
};
return CompletableFuture.completedFuture(conn);
}
The only constraint is to have the @Asynchronous method return Future or CompletionStage; otherwise, the implementation should throw an exception.