If you look at the JavaDoc for the getInputStream() method you are using (which actually exists in the URLConnection super class), you will see a "See Also" notation that points to the setReadTimeout(int) and getReadTimeout() methods. These can be used to set read timeouts.
The HttpURLConnection class also has a setConnectTimeout(int) method, which is also inherited from the URLConnection superclass. More info is available in the Javadoc for the method (see link). [ August 04, 2008: Message edited by: Mark Vedder ]