hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vijay kolli <vijay.kolli.andr...@gmail.com>
Subject set different socket timeout for same httpclient using MultiThreadedHttpConnectionManager
Date Thu, 01 Dec 2011 22:22:12 GMT
i have two threads using the same instance of the HTTPClientTest. two
threads call the send method on the same HTTPClientTest. how should i
set a different socket timeout for each of those threads that call the
send method. if i do something like this within the send method then
both threads executing the send method would have same socket timeout.
managerParams.setSoTimeout(60);connectionManager.setParams(managerParams);

how should i create a different socket timeout for multiple threads
executing the send method on the same instance of HTTPClientTest.

public class HTTPClientTest implements Runnable{
private HttpClient httpClient;
private MultiThreadedHttpConnectionManager connectionManager;
private HttpConnectionManagerParams managerParams;
private HttpClientTest()
{
     connectionManager = new MultiThreadedHttpConnectionManager();
     httpClient = new HttpClient(connectionManager);
}
public static synchronized HTTPClientTest getInstance()
{
    if(instance == null)
        instance = new HTTPClientTest();
    return instance;
}

public void send(String message, String url)
{
    PostMethod post = new PostMethod(url);
    String reply = "";
    String length = message.length() + "";
    post.setRequestHeader("Content-Length", length);
    try
    {
        System.out.println("HTTP request: " + message);
        StringRequestEntity postBody = new
StringRequestEntity(message, "text/xml", "UTF-8");
        post.setRequestEntity(postBody);
        int status = httpClient.executeMethod(post);
        System.out.println("HTTP status: " + status);
        reply = post.getResponseBodyAsString();
        System.out.println("HTTP Post response code: " + reply);

    }
    catch(HttpException e) {
        e.printStackTrace();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        post.releaseConnection();
    }

}
}

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


Mime
View raw message