question: public void terminate ( ) { this . terminated = true ; executorService . shutdown ( ) ; boolean finished = false ; boolean interrupted = false ; while ( ! finished ) { try { LOG . warning ( "Waiting for RADIUS thread pool's request handler(s) to finish processing." ) ; finished = executorService . awaitTermination ( RadiusServerConstants . THREAD_POOL_SHUTDOWN_WAIT_SECONDS , TimeUnit . SECONDS ) ; } catch ( final InterruptedException e ) { LOG . warning ( "InterruptedException caught while waiting for executorService to terminate." ) ; interrupted = true ; } } final Thread t = listenerThread ; if ( t != null ) { t . interrupt ( ) ; while ( listenerThread != null ) { LOG . warning ( "Waiting for RADIUS Listener to exit." ) ; try { Thread . sleep ( 200 ) ; } catch ( final InterruptedException e ) { } } } }
target:  Blocking call that terminates the thread pool, tells the listener to drop any new requests, waits until the thread pool is empty, and then interrupts the listener thread in case it is blocked waiting for new requests. We must wait for the pool to empty before interrupting the listener thread since that closes the channel if the thread is blocked on waiting for a new request and a closed channel then throws exceptions when any request handlers in-progress attempt to send their responses to their clients.