如何在Resteasy中使用“配置”启用连接池

时间:2019-02-05 13:41:39

标签: java rest jersey resteasy

我可以通过以下方式为球衣客户端启用连接池:

// From org.glassfish.jersey
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.READ_TIMEOUT, 7000);
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 2000);

// From org.apache.http
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(100);
connectionManager.setDefaultMaxPerRoute(20);

clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);

clientConfig.connectorProvider(new ApacheConnectorProvider());

Client client = ClientBuilder.newClient(clientConfig);

如何为Resteasy进行相同的配置?我不想在代码中使用具体的实现:

Client client = new ResteasyClientBuilder()
            .connectionPoolSize(100)
            .maxPooledPerRoute(20)
            .connectTimeout(2000, TimeUnit.MILLISECONDS)
            .readTimeout(7000, TimeUnit.MILLISECONDS)
            .build()

0 个答案:

没有答案