Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8237799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:35:25+00:00 2026-06-07T19:35:25+00:00

I have been trying to implement connection pool with Apache HttpClient (4.1.3) and ThreadSafeClientConnManager

  • 0

I have been trying to implement connection pool with Apache HttpClient (4.1.3) and ThreadSafeClientConnManager. And I faced with a problem when tried to set maximum connections for a route. Basically I followed examples from hc.apache.org/httpcomponents-client-ga/tutorial/html/connmgmt.html. For example, I want to set default connections per route to 10 and for ceratin route to 5 connections.

ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
cm.setMaxTotal(30);
cm.setDefaultMaxPerRoute(10);

HttpHost host = new HttpHost("hc.apache.org", 80, "http");
cm.setMaxForRoute(new HttpRoute(host, null, false), 5);

DefaultHttpClient httpClient = new DefaultHttpClient(cm);

And then I execute requests in threads:

  public void run() {
        try {
            HttpResponse response = this.httpClient.execute(this.httpget, this.context);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                // do something useful with the entity
            }
            // ensure the connection gets released to the manager
            EntityUtils.consume(entity);
        } catch (Exception ex) {
            this.httpget.abort();
        }
    }

And get logs like this:

DEBUG Thread-0 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-4 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-1 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-7 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-3 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-5 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-8 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-2 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-6 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager]: Get connection: HttpRoute[{}->http://hc.apache.org], timeout = 10000
DEBUG Thread-0 [org.apache.http.impl.conn.tsccm.ConnPoolByRoute]: [HttpRoute[{}->http://hc.apache.org]] total kept alive: 0, total issued: 0, total allocated: 0 out of 30
DEBUG Thread-0 [org.apache.http.impl.conn.tsccm.ConnPoolByRoute]: No free connections [HttpRoute[{}->http://hc.apache.org]][null]
DEBUG Thread-0 [org.apache.http.impl.conn.tsccm.ConnPoolByRoute]: Available capacity: 10 out of 10 [HttpRoute[{}->http://hc.apache.org]][null]
DEBUG Thread-0 [org.apache.http.impl.conn.tsccm.ConnPoolByRoute]: Creating new connection [HttpRoute[{}->http://hc.apache.org]]

Why did I get Available capacity: 10 out of 10 for this route, but not 5 as I specified?

Thanks

UPD: If I run this statement cm.getMaxForRoute(new HttpRoute(host, null, false)) after creating connection manager it will return 5.
But if I’ll try to check max connections for route in thread (after getting response):

HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
cm.getMaxForRoute(new HttpRoute(target));

Connection manager will return the same thing that in logs (10 connections).

I would be grateful for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:35:27+00:00Added an answer on June 7, 2026 at 7:35 pm

    It is strange, but it works well when I create HttpHost without port and protocol arguments.

    HttpHost host = new HttpHost("hc.apache.org");
    HttpRoute route = new HttpRoute(httpHost);
    conman.setMaxPerRoute(route, 13);
    

    PS: I have used httpclient-4.2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to implement connection pooling for my application using Apache HTTPClient (v4.1).
I have been having this annoying problem when trying to implement a picture gallery
I have been trying to implement a webDAV connection on an existing IIS ASP.NET
I have been trying to implement an upgrade plan for my Android app which
I have been trying to implement a GlassPane for my games' in-game HUD, but
Hello guys, I have been trying to implement the DSUM function but failed to
I have been trying for the past two days now to implement Admob ads
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I have been trying to implement a CheckBox Node Tree, where the parent nodes
I have been trying to implement remote debugging in two different scenarios both without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.