public void stop(int timeout) throws InterruptedException {
  if (!isclosed.compareAndSet(false,true)) {
    return;
  }
  List<WebSocket> socketsToClose=null;
synchronized (connections) {
    socketsToClose=new ArrayList<WebSocket>(connections);
  }
  for (  WebSocket ws : socketsToClose) {
    ws.close(CloseFrame.GOING_AWAY);
  }
synchronized (this) {
    if (selectorthread != null && selectorthread != Thread.currentThread()) {
      selector.wakeup();
      selectorthread.interrupt();
      selectorthread.join(timeout);
    }
  }
}

public void stop ( int timeout ) throws InterruptedException { if ( ! isclosed . compareAndSet ( false , true ) ) { return ; } List < WebSocket > socketsToClose = null ; synchronized ( connections ) { socketsToClose = new ArrayList < WebSocket > ( connections ) ; } for ( WebSocket ws : socketsToClose ) { ws . close ( CloseFrame . GOING_AWAY ) ; } synchronized ( this ) { if ( selectorthread != null && selectorthread != Thread . currentThread ( ) ) { selector . wakeup ( ) ; selectorthread . interrupt ( ) ; selectorthread . join ( timeout ) ; } } }
closes all connected clients sockets , then closes the underlying serversocketchannel , effectively killing the server socket selectorthread , freeing the port the server was bound to and stops all internal workerthreads . if this method is called before the server is started it will never start .
