public void cleanIdle(long delayMs) { Stopwatch start = executionTimeStats.start(); try { apacheHttpClient.getClientHandler().getHttpClient() .getConnectionManager() .closeIdleConnections(delayMs, TimeUnit.SECONDS); } catch (Throwable e) { logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@Override public void close() throws IOException { if (connectionManager != null && connectionConfig.shouldCloseIdleConnectionsAfterEachResponse()) { connectionManager.closeIdleConnections(connectionConfig.closeIdleConnectionConfig().getIdleTime(), connectionConfig.closeIdleConnectionConfig().getTimeUnit()); } if (wrapped != null) { wrapped.close(); } }
public void closeIdleConnections(final long idletime, final TimeUnit tunit) { delegate.closeIdleConnections(idletime, tunit); }
connectionManager.closeIdleConnections(MINUTE_IN_SECONDS, TimeUnit.SECONDS); } catch (Exception t) { log.warn("Unable to close idle connections", t);
@Override public void close() throws IOException { if(connectionManager != null && connectionConfig.shouldCloseIdleConnectionsAfterEachResponse()) { connectionManager.closeIdleConnections(connectionConfig.closeIdleConnectionConfig().getIdleTime(), connectionConfig.closeIdleConnectionConfig().getTimeUnit()); } wrapped.close(); }
@Override public void uninitialize() { if (_httpClient != null) { _httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS); _httpClient.getConnectionManager().shutdown(); } } }
@Override public void uninitialize() { if (_httpClient != null) { _httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS); _httpClient.getConnectionManager().shutdown(); } } }
public void closeIdleConnections() { log.debug("Closing idle HttpClient connections"); httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.MILLISECONDS); }
@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 ex) { // terminate } }
/** * 默认构造函数 */ public HttpsUtil() { this.charset = "UTF-8"; httpClient = this.setHttpClient(httpClient); httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BROWSER_COMPATIBILITY); httpClient.getConnectionManager().closeIdleConnections(30,TimeUnit.SECONDS); }
/** * POST the specified classpath resource to the specified HTTP endpoint. * @param endpointURL The HTTP endpoint URL. * @param requestResource The classpath resource to be posted to the endpoint. * @return The HTTP status code. */ public int postResourceAndGetStatus(String endpointURL, String requestResource) { HttpResponse httpResponse = postResourceAndGetMethod(endpointURL, requestResource); int status = httpResponse.getStatusLine().getStatusCode(); if ((httpResponse.getEntity() != null) && (httpResponse.getEntity().getContentLength() == -1)) { _httpClient.getConnectionManager().closeIdleConnections(0, TimeUnit.SECONDS); } else { EntityUtils.consumeQuietly(httpResponse.getEntity()); } return status; }
public void cleanup( final HttpRequestBase request ) { request.abort(); client.getConnectionManager() .closeExpiredConnections(); client.getConnectionManager() .closeIdleConnections( 2, TimeUnit.SECONDS ); } }
/** * 默认构造函数 */ public HttpUtil() { this.charset = "UTF-8"; PoolingClientConnectionManager pccm = new PoolingClientConnectionManager(); pccm.setMaxTotal(100); //设置整个连接池最大链接数 httpClient = new DefaultHttpClient(pccm); httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,CookiePolicy.BROWSER_COMPATIBILITY); httpClient.getConnectionManager().closeIdleConnections(30,TimeUnit.SECONDS); }
public void run() { try { while (!shutdown) { synchronized (this) { wait(1000); for (ClientConnectionManager connectionManager : connectionManagers) { connectionManager.closeExpiredConnections(); // TODO constant connectionManager.closeIdleConnections(30, TimeUnit.SECONDS); } } } } catch (InterruptedException ex) { shutdown(); } }
void cleanupConnections(){ connMgr.closeExpiredConnections(); connMgr.closeIdleConnections(connIdleEvictTimeMilliSeconds.get(), TimeUnit.MILLISECONDS); }
@Override public void run() { ASConnection asConnection = asConnectionWeakReference.get(); if (asConnection != null && !asConnection.shutdown) { try { asConnection.httpClient.getConnectionManager().closeExpiredConnections(); // Defensive call to close idle connections asConnection.httpClient.getConnectionManager().closeIdleConnections(asConnection.keepAliveTimeout, TimeUnit.MILLISECONDS); } finally { // Keep cleaning the target ASConnection while it has not been marked for collection cleanerExecutor.schedule(new ConnectionManagerCleaner(asConnection), asConnection.keepAliveTimeout, TimeUnit.MILLISECONDS); } } } }
@Override public void stop() throws Exception { if (this.idleConnectionReaper != null) { this.idleConnectionReaper.stop(); } if (getHttpClient() != null) { getHttpClient().getConnectionManager().closeExpiredConnections(); getHttpClient().getConnectionManager().closeIdleConnections( getStopIdleTimeout(), TimeUnit.MILLISECONDS); getHttpClient().getConnectionManager().shutdown(); getLogger().info("Stopping the HTTP client"); } }
public void cleanIdle(long delayMs) { Stopwatch start = executionTimeStats.start(); try { apacheHttpClient.getClientHandler().getHttpClient() .getConnectionManager() .closeIdleConnections(delayMs, TimeUnit.SECONDS); } catch (Throwable e) { logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
void cleanConnections() { httpclient.getConnectionManager().closeExpiredConnections(); httpclient.getConnectionManager().closeIdleConnections(2 * properties.getSocketTimeout(), TimeUnit.MILLISECONDS); }
void cleanConnections() { httpclient.getConnectionManager().closeExpiredConnections(); httpclient.getConnectionManager().closeIdleConnections(2 * properties.getSocketTimeout(), TimeUnit.MILLISECONDS); }