title: Closing a SocketChannel retrieved by ServerSocketChannel.accept()
body: <p>I have a timer on daemon thread which is continuously writing data into a <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/channels/SocketChannel.html" rel="nofollow"><code>SocketChannel</code></a>. In the main class I do not have the object reference of this socket channel, but I do have the reference of the <a href="http://docs.oracle.com/javase/6/docs/api/java/net/ServerSocket.html" rel="nofollow"><code>ServerSocket</code></a> to which this socket channel is connected. So I do this to close the channel. </p>
  
  <pre><code>socketChannel = serverSocket.accept();
  socketChannel.close();
  </code></pre>
  
  <p>But there is a latency involved in the deamon thread's socket channel close. Though they both refer to the same socket channel, the timer task writes into this socket channel even after the above <code>close()</code> is invoked until a few milliseconds.</p>
  
  <p>Kindly suggest how to ensure the close is made completed. This is an non blocking channel. </p>