4
我正在使用SwingWorker通過TCP連接讀取數據,並在返回時顯示。Swingworker Timeout
new SwingWorker<EnvInfoProto, Void>() {
@Override
public EnvInfoProto doInBackground() {
try {
xxx.writeTo(socket.getOutputStream());
return ProtoMsg.parseFrom(socket.getInputStream());
} catch(IOException ignore) { }
return null;
}
@Override
public void done() {
try {
UpdateGui(get());
} catch (Exception ignore) {}
}
}.execute();
問題出現在插座死了, writeTo之後,它會永久等待輸入到套接字上。一段時間後最簡單的方法是什麼?在這種情況下,this也是最好的解決方案嗎?我仍然會在該解決方案中使用迴轉工人嗎?
感謝