aspose file tools*
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 Spring in Action this week in the Spring 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: 19722
    
  20

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: 19722
    
  20

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...?