• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

URLConnection with time interval specified...?

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you checked the setConnectTimeout method?
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviously before, otherwise the call to connect() will not know about the new timeout.
 
prabhu pandurangan
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Rob

Thank you very much Rob. I have done it and my issue has been solved.
reply
    Bookmark Topic Watch Topic
  • New Topic