我正在使用URLConnection
的实例从网络服务器下载图片。这在大多数手机上运行良好。
我使用http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/作为进行并行下载的灵感。
我同时调用setConnectTimeout(timeout)
和setReadTimeout(timeout)
以便我可以从超时中恢复,因为我启动了许多并行获取图像的线程。
在三星Galaxy s2手机上,超时被忽略,一些线程下载挂起几分钟,然后抛出异常并重新下载 - 第二次下载成功。
抛出的异常如下所示:
DownloadTask, network timeout (attempt #0)
java.net.SocketTimeoutException: failed to connect to host (port 80) after 1000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:150)
libcore.io.IoBridge.connect(IoBridge.java:112)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
java.net.Socket.connect(Socket.java:842)
libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
..
这是三星Galaxy s2上已知的破坏行为吗?
Android版:4.0.4。