• Post Reply Bookmark Topic Watch Topic
  • New Topic

time task NOT using Threads  RSS feed

 
west james
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a way to time how long it takes to get a response back when I open a connection to a URL. I cannot use Threads, and I am looking for a way to close the URLconnection if I don't get a response back in a timely manner. Thanks.

Code Snippet:
URL url = "http://somewebsite.com"
con = (HttpURLConnection) url.openConnection();
myR = new BufferedReader(newInputStreamReader(con.getInputStream()));
String response = null;
while ((response = myR.readLine()) != null) {
String tester = response.toLowerCase();
if (tester.indexOf("up") >= 0) {
isUp = true;
}
}
break;
} catch (Exception e) {
isUp = false;
e.printStackTrace();
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

Sun JVM Implementation Specific Networking Properties, JDK 1.5.0 Documentation
 
west james
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am restricted to using JDK 1.3.

Suggestions?

thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!