Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 61896 invoked from network); 26 Mar 2007 13:40:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 26 Mar 2007 13:40:09 -0000 Received: (qmail 37515 invoked by uid 500); 26 Mar 2007 13:40:15 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 37493 invoked by uid 500); 26 Mar 2007 13:40:14 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 37458 invoked by uid 99); 26 Mar 2007 13:40:14 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2007 06:40:14 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [62.81.187.139] (HELO mail.interd4u.com) (62.81.187.139) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Mar 2007 06:40:04 -0700 Received: (qmail 9980 invoked by uid 512); 26 Mar 2007 13:39:39 -0000 Received: from 80.25.178.93 by jupiter (envelope-from , uid 508) with qmail-scanner-1.25st (clamdscan: 0.87/1149. spamassassin: 3.1.0. Clear:RC:1(80.25.178.93):. Processed in 0.126925 secs); 26 Mar 2007 13:39:39 -0000 Received: from 93.red-80-25-178.staticip.rima-tde.net (HELO Portatil04) (joan.balaguero@grupoventus.com@80.25.178.93) by jupiter with ESMTPA; 26 Mar 2007 13:39:39 -0000 From: =?iso-8859-1?Q?Joan_Balaguer=F3?= To: "'HttpClient User Discussion'" Subject: RE: PROBLEM WITH setMaxTotalConnections Date: Mon, 26 Mar 2007 15:39:38 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 x-mimeole: Produced By Microsoft MimeOLE V6.00.2900.3028 Thread-Index: AcdtSATcwiMtZD7WR2e9a7HiPeCtBACYyI7Q In-Reply-To: <1174653422.8211.34.camel@okhost> X-Qmail-Scanner-Message-ID: <11749163799229973@jupiter> X-Virus-Checked: Checked by ClamAV on apache.org Message-Id: <20070326134006.53F9510FB01E@herse.apache.org> Hello (again), I write a small program to test the maxTotalConnections. It's an application with a static httpClient (multithreaded). The main program inits this variable and starts 20 threads that use it to connect to our website. Again, I set the limit of active connections to 1. With these conditions, all threads are able to connect to destination perfectly (I've repeated the same with 200 threads). I don't know what to do to limit the number of connections. I don't know if I'm doing something wrong or if this is a bug of httpClient 3.1 Any suggestions will be much appreciated. Thanks, Joan. The code is the following: package com.vcfw.admin.utils; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.util.concurrent.CountDownLatch; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.PostMethod; public class testHttp { public static HttpClient objHttp = null; public static CountDownLatch cdlStart = new CountDownLatch(1); // Main. public static void main(String[] args) { // The thread Runnable r = new Runnable() { public void run() { try { // Wait until start... testHttp.cdlStart.await(); // Send the POST request. PostMethod objPost = new PostMethod("http://www.grupoventus.com"); testHttp.objHttp.executeMethod(objPost); // Read the response. BufferedInputStream bis = new BufferedInputStream(objPost.getResponseBodyAsStream()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[4098]; int numBytes; while ((numBytes = bis.read(buffer)) >= 0) bos.write(buffer, 0, numBytes); byte[] byteResponse = bos.toByteArray(); // Print the response. System.out.println(new String(byteResponse)); // Close all objPost.releaseConnection(); bis.close(); bos.close(); } catch (Exception e) { e.printStackTrace(); } } }; // MAIN PROGRAM. try { // Init the static httpClient objHttp = new HttpClient(new MultiThreadedHttpConnectionManager()); objHttp.getHttpConnectionManager().getParams().setMaxTotalConnections(1); objHttp.getHttpConnectionManager().getParams().setConnectionTimeout(2000); objHttp.getHttpConnectionManager().getParams().setSoTimeout(10000); objHttp.getHttpConnectionManager().getParams().setStaleCheckingEnabled(true) ; objHttp.getParams().setCookiePolicy(CookiePolicy.RFC_2109); // Start 20 threads that connect to "http://www.grupoventus.com". for (int i = 0; i < 20; i++) { new Thread(r).start(); } // Start !! cdlStart.countDown(); } catch (Exception e) { e.printStackTrace(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org