future< V > 접근 방식을 비동기 처리에 사용하면 다음과 같이 클라이언트 요청을 비동기적으로 호출할 수 있습니다.Using the future<V> approach to asynchronous processing, you can invoke a client request asynchronously, as follows:
// Java
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Client;
import java.util.concurrent.Future;
import javax.ws.rs.core.Response;
...
Client client = ClientBuilder.newClient();
Future<Response> futureResp = client.target("http://example.org/bookstore/books/123")
.request("application/xml")
.async()
.get();
...
// At a later time, check (and wait) for the response:
Response resp = futureResp.get();
// Java
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Client;
import java.util.concurrent.Future;
import javax.ws.rs.core.Response;
...
Client client = ClientBuilder.newClient();
Future<Response> futureResp = client.target("http://example.org/bookstore/books/123")
.request("application/xml")
.async()
.get();
...
// At a later time, check (and wait) for the response:
Response resp = futureResp.get();
Copy to ClipboardCopied!Toggle word wrapToggle overflow
입력한 답변에 유사한 방법을 사용할 수 있습니다. 예를 들어, type에 대한 응답을 얻으려면 BookInfo:
Client client = ClientBuilder.newClient();
Future<BookInfo> futureResp = client.target("http://example.org/bookstore/books/123")
.request("application/xml")
.async()
.get(BookInfo.class);
...
// At a later time, check (and wait) for the response:
BookInfo resp = futureResp.get();
Client client = ClientBuilder.newClient();
Future<BookInfo> futureResp = client.target("http://example.org/bookstore/books/123")
.request("application/xml")
.async()
.get(BookInfo.class);
...
// At a later time, check (and wait) for the response:
BookInfo resp = futureResp.get();
Copy to ClipboardCopied!Toggle word wrapToggle overflow