Java PoollightTPClientConnectionManager
我正在使用PoollightTPClientConnection重用连接。但是当我收集跟踪时,从同一客户机到同一服务器的每个请求都在建立连接。我已经上传了我的代码,可以从以下链接获得。你能告诉我失踪的佩斯吗 库Java PoollightTPClientConnectionManager,java,http,connection-pooling,Java,Http,Connection Pooling,我正在使用PoollightTPClientConnection重用连接。但是当我收集跟踪时,从同一客户机到同一服务器的每个请求都在建立连接。我已经上传了我的代码,可以从以下链接获得。你能告诉我失踪的佩斯吗 库 private JerseyClient getClient() { synchronized(this.lock) { if (this.client==null) { connManager = new PoolingHttpCli
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);