private void writeMessage(final ByteBuffer buffer){
  boolean threadShouldWrite=false;
synchronized (queue) {
    queue.add(buffer);
    if (!writing) {
      writing=true;
      threadShouldWrite=true;
    }
  }
  if (threadShouldWrite) {
    writeFromQueue();
  }
}

private void writeMessage ( final ByteBuffer buffer ) { boolean threadShouldWrite = false ; synchronized ( queue ) { queue . add ( buffer ) ; if ( ! writing ) { writing = true ; threadShouldWrite = true ; } } if ( threadShouldWrite ) { writeFromQueue ( ) ; } }
enqueues a write of the buffer to the channel . the call is asynchronous so the buffer is not safe to modify after passing the buffer here .
