• 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

setting time out

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need to set timeout for Connecting to the net.
Actucally I am doing a project using Tomcat as web server. In one of my modules my program need to connect to a website 'n' download the file.
Sometimes, for this to be happened its taking a lot of time. But I don't want my app to take much time. I want to set the maximum time to connect and download the file as 30 sec. How can I do this. I am using Windows Professional as OS 'n' Tomcat as my WebServer.
Can anybody help.........
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set a timeout on the connection with URL or the Apache HttpClient HttpURLConnection equivalent. But I don't think either let you set a timeout on the whole connect, send request, get response, disconnect operation.

I'm trying something right now that puts the http code in a runnable and the main thread looks like this:

There is a little more detail around synchronizing and threading, but that's the main idea. You can probably guess how Downloader notifies the main thread that it's done (if it finishes at all) and how it might use the interrupted() method to stop what it's doing. Does that look like it would help?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic