You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mugoma Joseph Okomba <mu...@yengas.com> on 2012/05/21 20:15:20 UTC

Calling closeIdleConnections ThreadSafeClientConnManager not working

Hello,

I am calling closeIdleConnections () on ThreadSafeClientConnManager object
every time a method is executed.

However I am ending up with a lot of connections in CLOSE_WAIT state for
long time. What can I do to ensure that these are closed?

Thanks.

Mugoma Joseph.

------------------

SAMPLE CODE:



	private static ThreadSafeClientConnManager connectionManager = null;
	private static final long MAX_CONNECTION_IDLE_TIME = 60000; // milliseconds

	static {
    connectionManager = new ThreadSafeClientConnManager();
    connectionManager.setDefaultMaxPerRoute(1000);
    connectionManager.setMaxTotal(1000);
    httpClient = new DefaultHttpClient(connectionManager);

	}

Then:


	/*
	* Check URL
	*/
	public void getObject(String url) throws Exception {

		try {

		}

		catch (java.io.InvalidClassException except) {

		}

		catch (IOException except) {
		  except.printStackTrace();
			throw except;
		}
		finally {
		  //IOUtils.closeQuietly(oin);

		  //getMethod.releaseConnection();
		  //connectionManager.closeIdleConnections(MAX_CONNECTION_IDLE_TIME);
			connectionManager.closeIdleConnections(MAX_CONNECTION_IDLE_TIME,
TimeUnit.MILLISECONDS);
			connectionManager.closeExpiredConnections();
		}


	}






---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org