<< Non-blocking IO and blocking queues | 首页 | What does the exception "java.net.SocketException: Connection reset by peer" mean? How can this be avoided? >>

java URLConnection and timeout and non-blocking io

自从JDK1.5以后java.net.URLConnection加入了setConnectTimeout(int timeout),但是也有办法在JDK1.5以前获得这个功能。
Adding Socket Timeout to java.net.URLConnection
HTTPClient Version 0.3-3
The Jakarta Commons HttpClient
另外,可以通过以下两个语句来设置相应的超时:
System.setProperty("sun.net.client.defaultConnectTimeout", 连接超时毫秒数);
System.setProperty("sun.net.client.defaultReadTimeout", 读数据超时毫秒数);
参见:http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
google:set Timeout on URLConnection

标签 :



发表评论 发送引用通报