I have a timer on daemon thread which is continuously writing data into a SocketChannel. In the main class I do not have the object reference of this socket channel, but I do have the reference of the ServerSocket to which this socket channel is connected. So I do this to close the channel.
socketChannel = serverSocket.accept();
socketChannel.close();
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 close() is invoked until a few milliseconds.
Kindly suggest how to ensure the close is made completed. This is an non blocking channel.