I have got 1000 dedicated Java threads where each thread polls a
corresponding url every one second.

Simplified version of the code is like this

MyThread extends() {
   Node node;
   MyThread(Node node) {
      this.node = node;
   }
   public void run() {
       Poller.poll()
   }
}

public class Poller {
    public static Node poll(Node node) {
        GetMethod method =  null;
        try {
            HttpClient client = new HttpClient(new
SimpleHttpConnectionManager(true));
            client.getParams().setParameter("http.socket.timeout", 120000);
        
            method = new GetMethod(node.getUrl());
            method.getParams().setSoTimeout(8000);

            client.executeMethod(method);

            method.getResponseHeaders();
            method.getResponseBody();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            method.releaseConnection();
        }
    }
}

The threads are run one second:

for (int i=0; i <1000; i++) {
    MyThread thread = threads.get(i) // threads  is a static field 
    if(thread.isAlive()) {
        // If the previous thread is still running, let it run.
    } else {
        thread.start();
    }
}

The problem is if I run the job every one second I get random exceptions 
like these:

java.net.BindException: Address already in use
 INFO httpclient.HttpMethodDirector: I/O exception (java.net.BindException)
caught when processing request: Address already in use
 INFO httpclient.HttpMethodDirector: Retrying request

But if I run the job every 2 seconds or more, everything runs fine.

I even tried shutting down the instance of SimpleHttpConnectionManager()
using shutDown() with no effect.

It looks like if when myThread has finished running, the HttpClient it
started hasn't shutdown even though I told it to release conenction and/or
shutdown the manager.

Any ideas?


-- 
View this message in context: 
http://old.nabble.com/BindException-while-using-HttpClient-under-load-tp28662810p28662810.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to