Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpcomponents Wiki" for change notification.
The following page has been changed by OlegKalnichevski: http://wiki.apache.org/HttpComponents/HttpClientTutorial ------------------------------------------------------------------------------ === Simple connection manager === - One connection per client. - + SingleClientConnManager is a simple connection manager that maintains only one connection at a time. Even though this class is thread-safe it ought to be used by one execution thread only. SingleClientConnManager will make an effort to reuse the connection for subsequent requests with the same route. It will, however, close the existing connection and open it for the given route, if the route of the persistent connection does not match that of the connection request. If the connection has been already been allocated IllegalStateException is thrown. + + SingleClientConnManager is used by HttpClient per default. + === Pooling connection manager === + ThreadSafeClientConnManager is a more complex implementation that manages a pool of client connections and is able to service connection requests from multiple execution threads. Connections are pooled on a per route basis. A request for a route which already the manager has persistent connections for available in the pool will be services by leasing a connection from the pool rather than creating a brand new connection. - Thread-safe connection pool that can be utilized by multiple worker threads. - Connection pool configuration. Total max connections. Max connections per route. + ThreadSafeClientConnManager maintains a maximum limit of connection on a per route basis and in total. Per default this implementation will create no more than than 2 concurrent connections per given route and no more 20 connections in total. For many real-world applications these limits may prove too constraining, especially if they use HTTP as a transport protocol for their services. Connection limits, however, can be adjusted using HTTP parameters. + + This example shows how the connection pool parameters can be adjusted: + + {{{ + HttpParams params = new BasicHttpParams(); + // Increase max total connection to 200 + ConnManagerParams.setMaxTotalConnections(params, 200); + // Increase default max connection per route to 20 + ConnPerRouteBean connPerRoute = new ConnPerRouteBean(20); + // Increase max connections for localhost:80 to 50 + HttpHost localhost = new HttpHost("locahost", 80); + connPerRoute.setMaxForRoute(new HttpRoute(localhost), 50); + ConnManagerParams.setMaxConnectionsPerRoute(params, connPerRoute); + + SchemeRegistry schemeRegistry = new SchemeRegistry(); + schemeRegistry.register( + new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); + schemeRegistry.register( + new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); + + ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); + HttpClient httpClient = new DefaultHttpClient(cm, params); + }}} + == Stateful connections == NTLM connections. SSL connections with client authentication. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
