@ SuppressWarnings ( "checkstyle:magicnumber" ) private void doClose ( ) throws IOException { logger . debug ( "Gracefully shutting down Sentry async threads." ) ; closed = true ; executorService . shutdown ( ) ; try { if ( shutdownTimeout == - 1L ) { // Block until the executor terminates, but log periodically. long waitBetweenLoggingMs = 5000L ; while ( true ) { if ( executorService . awaitTermination ( waitBetweenLoggingMs , TimeUnit . MILLISECONDS ) ) { break ; } logger . debug ( "Still waiting on async executor to terminate." ) ; } } else if ( ! executorService . awaitTermination ( shutdownTimeout , TimeUnit . MILLISECONDS ) ) { logger . warn ( "Graceful shutdown took too much time, forcing the shutdown." ) ; List < Runnable > tasks = executorService . shutdownNow ( ) ; logger . warn ( "{} tasks failed to execute before shutdown." , tasks . size ( ) ) ; } logger . debug ( "Shutdown finished." ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; logger . warn ( "Graceful shutdown interrupted, forcing the shutdown." ) ; List < Runnable > tasks = executorService . shutdownNow ( ) ; logger . warn ( "{} tasks failed to execute before shutdown." , tasks . size ( ) ) ; } finally { actualConnection . close ( ) ; } }
Close the connection whether it s from the shutdown hook or not .