hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 37561] New: - Multiple HttpClient instances and thread safety?
Date Fri, 18 Nov 2005 20:16:16 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37561>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37561

           Summary: Multiple HttpClient instances and thread safety?
           Product: HttpClient
           Version: 3.0 RC4
          Platform: Other
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HttpClient
        AssignedTo: httpclient-dev@jakarta.apache.org
        ReportedBy: kirk.w.rasmussen@bankofamerica.com


Using HttpClient as a crude load tester with 75 agents running I am seeing the
following on occasion:

WARNING: SimpleHttpConnectionManager being used incorrectly.  Be sure that
HttpMethod.releaseConnection() is always called and that only one thread and/or
method is using this connection manager at a time.

The code that I am running is:

    public Agent() throws Exception {
        HttpClientParams params = new
HttpClientParams(HttpClientParams.getDefaultParams());
        params.setConnectionManagerTimeout(60000L);
        params.setSoTimeout(60000);
        http = new HttpClient(params);
    }

...
        String[] urls = { ... }
        for (String url : urls) {
            GetMethod method = new GetMethod(url);
            try {
                http.executeMethod(method);
                int status = method.getStatusCode();
                if (status != HttpStatus.SC_OK) {
                    throw new IOException("Failed to load target URL: " + method);
                }
                //System.out.println(method.getResponseBodyAsString());
            } finally {
                method.releaseConnection();
            }
        }

Each thread gets its own HttpClient and method.releaseConnection is always called.

The code to launch the threads is as follows:

        ExecutorService pool = Executors.newFixedThreadPool(threads);
        List<Agent> agents = new ArrayList<Agent>();
        results = new LinkedList<Future>();
        for (int i=0; i < runs; i++) {
            results.add(pool.submit(new AcidAgent()));
        }

        while (! results.isEmpty()) {
            Future f = results.get(0);
            try {
                Object result = f.get(60, TimeUnit.SECONDS);
                results.remove(f);
                System.out.println(result);
            } catch (TimeoutException ex ) {
                System.out.println("Incomplete");
            } catch (Exception ex) {
                System.out.println(ex);
                if (f.isDone()) {
                    results.remove(f);
                }
            }
        }

Am I doing something wrong?

Thanks

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message