idleconnectionvictor是否关闭poolighttpclientconnectionmanager?

hgc7kmma  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(223)

我正在使用 PoolingHttpClientConnectionManager 在resttemplate配置中。当使用此工具时,我的intellijide会显示如下警告 'PoolingHttpClientConnectionManager' should be opened in front of a 'try' block and closed in the corresponding 'finally' block .
但当我和 IdleConnectionEvictor 此警告未显示。
下面是我的代码

final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
        connectionManager.setDefaultMaxPerRoute(connectionPooling.getMaxConnections());
        connectionManager.setMaxTotal(connectionPooling.getMaxConnections());

        final HttpClient httpclient = HttpClientBuilder
            .create()
            .setConnectionManager(connectionManager)
            .build();

        final HttpComponentsClientHttpRequestFactory connectionFactory =
            new HttpComponentsClientHttpRequestFactory(httpclient);
        connectionFactory.setConnectTimeout(connectionTimeout);
        connectionFactory.setReadTimeout(readTimeout);
        connectionFactory.setConnectionRequestTimeout(connectionPooling.getConnectionRequestTimeoutMillis());
        final BufferingClientHttpRequestFactory clientHttpRequestFactory =
            new BufferingClientHttpRequestFactory(connectionFactory);

       final RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);

        final IdleConnectionEvictor idleConnectionTimeoutThread =
            new IdleConnectionEvictor(connectionManager,
                connectionPooling.getIdleConnectionCheckMillis(), TimeUnit.MILLISECONDS,
                connectionPooling.getIdleConnectionTimeoutMillis(), TimeUnit.MILLISECONDS);
        idleConnectionTimeoutThread.start();

请解释一下它的工作原理

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题