title: Swingworker Timeout
body: <p>I am using a SwingWorker to read data over a TCP connection and display when it comes back.</p>
  
  <pre><code>new SwingWorker&lt;EnvInfoProto, Void&gt;() {
    @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();
  </code></pre>
  
  <p>The problem arises when the socket is dead, e.g. after writeTo it waits eternally for input on the socket. What is the easiest way to timeout after a while? Is <a href="https://stackoverflow.com/questions/2356670/timeout-a-task-with-javas-swingworker">this</a> also the best solution in this case? Would I still use a swingworker in that solution?</p>
  
  <p>Thanks</p>