@ SneakyThrows public void gracefullyShutdown ( Duration timeout ) { logger . info ( "Shutting down..." ) ; if ( ! shuttingDown ) { synchronized ( this ) { shuttingDown = true ; threadPoolExecutor . shutdown ( ) ; } // stops jobs that have not yet started to be executed for ( Job job : jobStatus ( ) ) { Runnable runningJob = job . runningJob ( ) ; if ( runningJob != null ) { threadPoolExecutor . remove ( runningJob ) ; } job . status ( JobStatus . DONE ) ; } synchronized ( launcherNotifier ) { launcherNotifier . set ( false ) ; launcherNotifier . notify ( ) ; } } threadPoolExecutor . awaitTermination ( timeout . toMillis ( ) , TimeUnit . MILLISECONDS ) ; }
Wait until the current running jobs are executed and cancel jobs that are planned to be executed .