我正在使用PoolingHTTPClientConnection重用连接。但是当我收集跟踪时,来自同一客户端的每个请求都在建立连接。我上传了我的代码,可从以下链接获得。能不能让我知道失踪的人。
https://drive.google.com/file/d/0BxwfXmp0DqbHNjdYNXlhbXEwMmM/view?usp=sharing
库
private JerseyClient getClient() {
synchronized(this.lock) {
if (this.client==null) {
connManager = new PoolingHttpClientConnectionManager();
connManager.setMaxTotal(this.maxTotalconnections);
connManager.setDefaultMaxPerRoute(this.defaultMaxconnectionsPerRoute);
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.READ_TIMEOUT, this.readTimeoutInMs );
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, this.connectTimeoutInMs);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connManager);
clientConfig.connectorProvider(new ApacheConnectorProvider());
client = JerseyClientBuilder.createClient(clientConfig);
//client.register(JacksonFeature.class);
return client;
}
}
return this.client;
}
public Response invokeGETResource(String URI, String path, String acceptType, MultivaluedMap headers, Map resolveTemplate) {
Response resp = null;
if (URI==null || resolveTemplate.size() <= 0 || acceptType == null)
{
return resp;
}
jWebTarget = getClient().target(URI).path(path);
if (resolveTemplate.size() > 0)
{
jWebTarget = jWebTarget.resolveTemplates(resolveTemplate);
}
jInvBuilder = jWebTarget.request().accept(acceptType);
if (headers.size() > 0)
{
jInvBuilder = jInvBuilder.headers(headers);
}
resp = jInvBuilder.get();
return resp;
}
客户端
private IRestClient2 httpClient;
resp = httpClient.invokeGETResource(URI, "", MediaType.APPLICATION_JSON, header, templateResolve);
提前谢谢你:)