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?
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 11 years ago
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.
I have no java certifications. This makes me a bad programmer. Ignore my post.
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads