Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

setting time out  RSS feed

 
Sagar kanchi
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • 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.........
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!