我是 Thread 的新手,想使用 SwingWorker 来更新我的 GUI,而另一个线程正在分析一些 html 并下载文件..
这是我的代码:
protected Void doInBackground() throws Exception {
analyzeHTML();
download();
return null;
}
整个通话有时会失败:
SEVERE: null
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:429)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:446)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
at hanserdownloader.LinkProcessorThread.analyzeHTML(LinkProcessorThread.java:208)
at hanserdownloader.LinkProcessorThread.doInBackground(LinkProcessorThread.java:139)
at hanserdownloader.LinkProcessorThread.doInBackground(LinkProcessorThread.java:113)
at javax.swing.SwingWorker$1.call(SwingWorker.java:296)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at javax.swing.SwingWorker.run(SwingWorker.java:335)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
所以我的问题是:
当从 one/doInBackground() 调用这两种方法时,它们是否也在工作线程中运行。应该是吧?
似乎是一个愚蠢的问题,但我有点不安,如果这个超时错误不是真的由一些线程混乱(而不是真正的http超时)产生的......
谢谢您的帮助!