void shutdown ( ) throws InterruptedException { List < NGSession > allSessions ; synchronized ( lock ) { done = true ; allSessions = Stream . concat ( workingPool . stream ( ) , idlePool . stream ( ) ) . collect ( Collectors . toList ( ) ) ; idlePool . clear ( ) ; workingPool . clear ( ) ; } for ( NGSession session : allSessions ) { session . shutdown ( ) ; } // wait for all sessions to complete by either returning from waiting state or finishing their // nails long start = System . nanoTime ( ) ; for ( NGSession session : allSessions ) { long timeout = NGConstants . SESSION_TERMINATION_TIMEOUT_MILLIS - TimeUnit . MILLISECONDS . convert ( System . nanoTime ( ) - start , TimeUnit . NANOSECONDS ) ; if ( timeout < 1 ) { // Give all threads a chance to finish or pick up already finished threads timeout = 1 ; } session . join ( timeout ) ; if ( session . isAlive ( ) ) { throw new IllegalStateException ( "NGSession has not completed in " + NGConstants . SESSION_TERMINATION_TIMEOUT_MILLIS + " ms" ) ; } } }
Shuts down the pool . The function waits for running nails to finish .