Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Kill an HttpURLConnection  RSS feed

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an HttpURLConnection that talks to a partner system which sometimes never responds. The code to read the response hangs forever. I'd like to impose my own timeout on the wait so I handed the connection to a timer tasks that waits 30 seconds and then calls disconnect() on the connection. This doesn't interrup the main thread, though.

Given an HttpURLConnection, any idea how I can blow the sucker up? Or maybe kill the other thread?
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using sun JDK1.4 then you could use the sun specific properties


sun.net.client.defaultConnectTimeout (default: -1)
sun.net.client.defaultReadTimeout (default: -1)
These properties specify the default connect and read timeout (resp.) for the protocol handler used by java.net.URLConnection.

sun.net.client.defaultConnectTimeout specifies the timeout (in milliseconds) to establish the connection to the host. For example for http connections it is the timeout when establishing the connection to the http server. For ftp connection it is the timeout when establishing the connection to ftp servers.

sun.net.client.defaultReadTimeout specifies the timeout (in milliseconds) when reading from input stream when a connection is established to a resource.


If you're using sun jdk1.3 then you're probably out of luck.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!