Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2005

Tip: Looking for answers? Try searching our database.

HttpURLConnection timeout?

Thread view: 
Jack - 15 Apr 2004 00:59 GMT
Hi,

Is it possible to set a timeout when opening a connection to an
HttpURLConnection?

For example, is it possible to make the connection call and limit it to 5
seconds before a response is generated?

That is, I don't want to have to wait for the "default" timeout.

Thanks for any info.

Jack
Dave Ockwell-Jenner - 16 Apr 2004 20:05 GMT
> Hi,
>
[quoted text clipped - 5 lines]
>
> That is, I don't want to have to wait for the "default" timeout.
[snip]

You can't do this using Sun's classes unless you use a "private"
property setting.  Unfortunately, the setting is not guaranteed to
remain the same (or remain at all).

I've just been working on a similar task and used the
Commons-HTTPClient[1] from Apache.  It allows you to specify both a
connection timeout and also a timeout when reading the response.  It
works superbly!

[1] http://jakarta.apache.org/commons/httpclient/

Signature

Dave Ockwell-Jenner
Solar Nexus Solutions
http://www.solar-nexus.com/

Adam P. Jenkins - 13 Apr 2005 02:59 GMT
>> Hi,
>>
[quoted text clipped - 18 lines]
>
> [1] http://jakarta.apache.org/commons/httpclient/

Actually Sun has added this in Java 1.5.  See the java.net.URLConnection
    setConnectionTimeout() and setReadTimeout() methods.  If you need
to use an earlier version of Java then the Jakarta HTTPClient package
works great.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.