我有一个非常微笑的球衣客户端,如下所示。如果客户端和服务器在同一台机器上
response.getEntity(String.class)
行只需要几纳秒,但如果客户端和服务器位于不同的机器上,则需要250-300毫秒。我在球衣1和球衣2上试过这个,但结果并没有改变。你有什么想法吗?
package com.mkyong.client;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
public class JerseyClientGet {
public static void main(String[] args) {
try {
Client client = Client.create();
WebResource webResource = client
.resource("http://localhost:8080/RESTfulExample/rest/json/metallica/get");
ClientResponse response = webResource.accept("application/json")
.get(ClientResponse.class);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatus());
}
String output = response.getEntity(String.class);
System.out.println("Output from Server .... \n");
System.out.println(output);
} catch (Exception e) {
e.printStackTrace();
}
}
}