Subscribe to RSS Feed
Twitter
HIRE ME! home  archives  about  blogroll

URL connection timeout

09 Oct 2003

i’m looking for a way to set the connection timeout on a URL object. the only way i found of doing this at the moment is by setting the following property : sun.net.client.defaultConnectTimeout

but when you read this : These properties may not be supported in future releases. then i don’t think this is the right way of doing it … but it works like a charm :)

      System.getProperties().put( “sun.net.client.defaultConnectTimeout”, “1” );
      url = new URL;
      start = System.currentTimeMillis();
      try {
         url.openStream();
      } catch (e) {
         print(e);
      }
      stop = System.currentTimeMillis();
      print(stop – start);

this is why i love beanshell, you can very quickly test this kind of stuff :)

blog comments powered by Disqus