@Override public void closeIdleConnections(long idleTimeout, TimeUnit unit) { connectionManager.closeIdleConnections(idleTimeout, unit); } }
@Override public void run() { try { while (!shutdown) { synchronized (this) { wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS); for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) { connectionManager.closeExpiredConnections(); connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS); } } } } catch (InterruptedException ex) { shutdown(); } }
@Override public void run() { try { while (!shutdown) { synchronized (this) { wait(HTTPCLIENTCONNECTIONMANAGER_CLOSEWAITTIME_MS); for (PoolingHttpClientConnectionManager connectionManager : connectionManagers) { connectionManager.closeExpiredConnections(); connectionManager.closeIdleConnections(HTTPCLIENTCONNECTIONMANAGER_CLOSEIDLETIME_S, TimeUnit.SECONDS); } } } } catch (InterruptedException ex) { shutdown(); } }
@Override public void run() { try { while (!shutdown) { synchronized (this) { wait(5000); // Close expired connections connMgr.closeExpiredConnections(); // Optionally, close connections that have been idle longer than 30 sec connMgr.closeIdleConnections(30, TimeUnit.SECONDS); } } } catch (InterruptedException ignored) { // terminate } }
/** * release connections from the pool * * @param idleSeconds idle seconds, longer than the configured value will be evicted */ public void releaseConnection(long idleSeconds) { this.connManager.closeExpiredConnections(); this.connManager.closeIdleConnections(idleSeconds, TimeUnit.SECONDS); } }
@Override public void run() { try { // Holds the stop request that stopped the process. Stop stopRequest; // Every 5 seconds. while ((stopRequest = stopSignal.poll(5, TimeUnit.SECONDS)) == null) { // Close expired connections cm.closeExpiredConnections(); // Optionally, close connections that have been idle too long. cm.closeIdleConnections(60, TimeUnit.SECONDS); // Look at pool stats. log.debug("Stats: {}", cm.getTotalStats()); } // Acknowledge the stop request. stopRequest.stopped(); } catch (InterruptedException ex) { // terminate } }
/** * Closes all idle persistent connections used by the internal pool. * @since 4.4 */ public static void closeIdleConnections() { CONNMGR.closeIdleConnections(0, TimeUnit.MICROSECONDS); }
@Override public void closeIdleConnections( final long idletime, final TimeUnit tunit ) { logger.trace( "Closing idle connections" ); connectionManager.closeIdleConnections( idletime, tunit ); }
/** * release connections from the pool * * @param idleSeconds idle seconds, longer than the configured value will be evicted */ public void releaseConnection(long idleSeconds) { this.connManager.closeExpiredConnections(); this.connManager.closeIdleConnections(idleSeconds, TimeUnit.SECONDS); } }
public static void reset() { cm.closeIdleConnections(1000,TimeUnit.SECONDS); cm.closeExpiredConnections(); } /**
/** * @param mapHttpClientPerHttpClientKey */ private void closeCurrentConnections( Map<HttpClientKey, Pair<CloseableHttpClient, PoolingHttpClientConnectionManager>> mapHttpClientPerHttpClientKey) { for (Pair<CloseableHttpClient, PoolingHttpClientConnectionManager> pair : mapHttpClientPerHttpClientKey.values()) { PoolingHttpClientConnectionManager poolingHttpClientConnectionManager = pair.getRight(); poolingHttpClientConnectionManager.closeExpiredConnections(); poolingHttpClientConnectionManager.closeIdleConnections(1L, TimeUnit.MICROSECONDS); } }
@Override public void run() { try { connManager.closeIdleConnections(30, TimeUnit.SECONDS); connManager.closeExpiredConnections(); } catch (Throwable e) { logger.warn("fail to close idle connections.{}", e.getMessage()); } } };
/** * Closes connections that have been idle for at least the given amount of time. A value of 0 means * <em>never</em> timeout. * * @param timeout the timeout value in milliseconds * @see PoolingHttpClientConnectionManager#closeIdleConnections(long, java.util.concurrent.TimeUnit) */ public void closeIdleConnections(long timeout) { if (timeout < 0) { throw new IllegalArgumentException("timeout must be a non-negative value"); } ((PoolingHttpClientConnectionManager)getConnPoolControl()).closeIdleConnections(timeout, TimeUnit.MILLISECONDS); }
void cleanUp() { manager.closeExpiredConnections(); manager.closeIdleConnections(30, TimeUnit.SECONDS); }
@Override @Scheduled(fixedDelay = 10000) public void run() { try { if (connectionManager != null) { LOGGER.trace("run IdleConnectionMonitor - Closing expired and idle connections..."); connectionManager.closeExpiredConnections(); connectionManager.closeIdleConnections(p.getCloseIdleConnectionWaitTimeSecs(), TimeUnit.SECONDS); } else { LOGGER.trace("run IdleConnectionMonitor - Http Client Connection manager is not initialised"); } } catch (Exception e) { LOGGER.error("run IdleConnectionMonitor - Exception occurred. msg={}, e={}", e.getMessage(), e); } } };
@Override protected void closeIdleConnection(PoolingHttpClientConnectionManager manager) { try { manager.closeExpiredConnections(); } catch (final Throwable t) { _logger.warn("Error closing expired connections for sync pool", t); } try { manager.closeIdleConnections(idleTime(), TimeUnit.MILLISECONDS); } catch (final Throwable t) { _logger.warn("Error closing idle connections for sync pool", t); } }
@Override protected void closeIdleConnection(PoolingHttpClientConnectionManager manager) { try { manager.closeExpiredConnections(); } catch (final Throwable t) { _logger.warn("Error closing expired connections for sync pool", t); } try { manager.closeIdleConnections(idleTime(), TimeUnit.MILLISECONDS); } catch (final Throwable t) { _logger.warn("Error closing idle connections for sync pool", t); } }
private CloseableHttpClient getHttpClient() { if (this.httpClient != null) { return this.httpClient; } PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(); connManager.setDefaultMaxPerRoute(6); connManager.setMaxTotal(20); connManager.closeIdleConnections(120, TimeUnit.SECONDS); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); //SOFATracer SofaTracerHttpClientBuilder.clientBuilder(httpClientBuilder); httpClient = httpClientBuilder.setConnectionManager(connManager).disableAutomaticRetries() .setUserAgent("CLIENT_VERSION").build(); return httpClient; } }
void closeIdleConnections() { if (asyncConnectionManager != null) { asyncConnectionManager.closeExpiredConnections(); asyncConnectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT, TimeUnit.SECONDS); } if (syncConnectionManager != null) { syncConnectionManager.closeExpiredConnections(); syncConnectionManager.closeIdleConnections(IDLE_CONNECTION_TIMEOUT, TimeUnit.SECONDS); } }
/** * */ public DefaultConnector() { final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.closeIdleConnections(120, TimeUnit.SECONDS); // would be nice to set this from outside -> keep alive final SocketConfig sConfig = SocketConfig.custom().setSoKeepAlive(true).setSoTimeout(Context.SOCKET_TO).build(); cm.setDefaultSocketConfig(sConfig); cm.setMaxTotal(150); cm.setDefaultMaxPerRoute(150); cm.setValidateAfterInactivity(0); final HttpRequestRetryHandler rh = new DefaultHttpRequestRetryHandler(3, true); httpClient = HttpClients.custom().setRetryHandler(rh).setConnectionManager(cm).build(); }