我可以为底层图像下载请求设置HtmlUnit.getWidth()的超时

时间:2012-10-09 14:28:28

标签: timeout htmlunit

问题是:如何在调用HtmlImage.getHeight或getWidth()之前设置超时?

上下文:

我正在使用HtmlUnit 2.10来获取元素的实际图像大小,并且我能够强制执行文件下载。据说触发图像下载的呼叫是 HtmlImage.getHeight()或getWidth()。然而,似乎在某些情况下(可能是当网站很慢或某些东西......)这个调用返回需要15分钟,虽然它似乎恢复正常,但我真的不想打断线程。 在这15分钟的整个过程中,一个threaddump下面看起来像这样。

测试问题的网址: http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/10/121006_feature_china_highway_jams.shtml

"R-pool-5-thread-19" daemon prio=10 tid=0x525d4400 nid=0x4400 runnable [0x513c7000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)
at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90)
at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:712)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:517)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at com.gargoylesoftware.htmlunit.HttpWebConnection.getResponse(HttpWebConnection.java:172)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseFromWebConnection(WebClient.java:1460)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponse(WebClient.java:1379)
at com.gargoylesoftware.htmlunit.html.HtmlImage.downloadImageIfNeeded(HtmlImage.java:374)
at com.gargoylesoftware.htmlunit.html.HtmlImage.readImageIfNeeded(HtmlImage.java:381)
at com.gargoylesoftware.htmlunit.html.HtmlImage.getHeight(HtmlImage.java:311)

0 个答案:

没有答案