title: Interrupting thread which is blocked waiting on IO from socket?
body: <p>I have an app that listens to incoming connections on a specified hostname and port. The listening is invoked with the method <code>listen()</code> (see below), which waits constantly for an incoming connection using <code>ServerSocket.accept()</code>, creating a new <code>Thread</code> to handle the input stream.</p>
  
  <pre><code>private ServerSocket serverSocket;
  private Thread listenerThread;
  
  public void listen() throws IOException {
      this.listenerThread = new Thread(new Runnable() {
  
          @Override
          public void run() {
              while (true) {
                  try {
                      Socket socket = TheServerClass.this.serverSocket.accept();
                      // Create new thread to handle the incoming connection
                  }
                  catch (IOException exc) { }
              }
          }
      });
      this.listenerThread.start();
  }
  </code></pre>
  
  <p>Now I want to stop the running of <code>listenerThread</code>. But when I call <code>this.listenerThread.interrupt()</code>, this doesn't work.<br>
  I thought you can stop a thread by interrupting it, so why isn't that working?</p>
  
  <p>(<strong>Notice:</strong> A possible solution is to close the <code>ServerSocket</code> using <code>this.serverSocket.close()</code>, but can it be accomplished with <code>interrupt()</code> or something?)</p>