How to set an Apache HttpClient timeout value (Java)

How to set a timeout on an Apache HttpClient:

HttpClient client = new DefaultHttpClient();
client.getParams().setParameter("http.socket.timeout", new Integer(10*1000));

I like to make my code easier to read, so I use the "10*1000" there to make it easier to read that I want a ten-second timeout.

Share it!

There’s just one person behind this website; if this article was helpful (or interesting), I’d appreciate it if you’d share it. Thanks, Al.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.