com.sun.jersey.api.client.WebResource.Builder.get 方法会等待响应吗?

Will the com.sun.jersey.api.client.WebResource.Builder.get method wait for response?

我正在开发 jersey-client 1.19。我有这些代码行来向服务器提交请求并获得响应:

Client client = Client.create();

WebResource webResource = client.resource("http://localhost:8080/RESTfulExample/rest/json/metallica/post");
String input = "{\"singer\":\"Metallica\",\"title\":\"Fade To Black\"}";

ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);

if (response.getStatus() != 201) {
    throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}

我有一个问题,当 post 方法执行时,如果与服务器的连接出现问题(互联网连接速度较慢,它将在 3 分钟后响应),那么代码 if (response.getStatus() != 201) 将保持 运行 还是等待 post 执行的响应?

下一行是对服务器的 blocking (synchronous) 调用 -

ClientResponse response = webResource.type("application/json").post(ClientResponse.class, input);

表示这一行等待服务器响应。在收到来自服务器的 success/error 响应之前,程序不会在此行之后继续执行。

表示代码写在这一行之后 -

if (response.getStatus() != 201) {
    throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}

它将等待上一行的完全执行(post 方法响应)。

有关信息,Jersey 还支持 non-blocking (asynchronous) 调用服务器。检查 here 了解详情。另外,我建议不要使用旧版本的 jersey。当前版本是 2.5.1 jersey 1.x and 2.x

之间有很多区别