1

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

语境:

我正在使用 HtmlUnit 2.10 来获取元素的实际图像大小,并且能够强制进行文件下载。据说触发图像下载的调用是 HtmlImage.getHeight() 或 getWidth()。但是,似乎在某些情况下(可能是网站速度慢或其他情况......)此调用需要 15 分钟才能返回,虽然它似乎恢复正常,但我也不想中断线程。在这 15 分钟的整个过程中,下面的线程转储看起来像这样。

问题测试网址: 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)
4

0 回答 0