This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes URLConnection with time interval specified...? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "URLConnection with time interval specified...?" Watch "URLConnection with time interval specified...?" New topic
Author

URLConnection with time interval specified...?

prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
Hi Members,

I have to connect a URL; but for only certain time interval. Now im using UrlConnection.connect(); But it loops around for one or more attempt whether it could make a connection. Instead i need to connect for certain time interval say 3 seconds; if the url specified is connected within the time interval; it should return 'true' or if it fails to connect the url with in the time interval specified it should return 'false'.

I need a sample java code to perform this action.


Regards,
Prabhu.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Have you checked the setConnectTimeout method?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
@Rob

URL url = new URL(urlName);
URLConnection connection = url.openConnection();
connection.connect();

This is the code im using; how to use setConnectTimeOut();
before im attempting to connect() or after that.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Obviously before, otherwise the call to connect() will not know about the new timeout.
prabhu pandurangan
Ranch Hand

Joined: May 23, 2008
Posts: 120
@Rob

Thank you very much Rob. I have done it and my issue has been solved.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URLConnection with time interval specified...?
 
Similar Threads
Calling Https url
setInterval and clearInterval functions
How to retrieve data from database every 10 minutes?
Converting millisecs to hour, minute, seconds.
Question on container-managed authentication