private synchronized void asyncResponse ( String command , SocketChannel sc ) { if ( closed ) { Utils . tryToClose ( sc ) ; } else { Thread thread = new Thread ( new ResponseThread ( command , sc ) , "kernel-" + command + "-command-response" ) ; // We allow a maximum of one outstanding status start or stop command Thread oldThread = responseThread . getAndSet ( thread ) ; if ( oldThread != null ) { oldThread . interrupt ( ) ; } thread . start ( ) ; } }
Creates a single thread to wait for the command to complete then respond .