@ SuppressWarnings ( "FutureReturnValueIgnored" ) private void deleteProjectDirsInParallel ( final ImmutableSet < File > projectDirsToDelete ) { final int CLEANING_SERVICE_THREAD_NUM = 8 ; final ExecutorService deletionService = Executors . newFixedThreadPool ( CLEANING_SERVICE_THREAD_NUM ) ; for ( final File toDelete : projectDirsToDelete ) { deletionService . submit ( ( ) -> { log . info ( "Deleting project dir {} from project cache to free up space" , toDelete ) ; FileIOUtils . deleteDirectorySilently ( toDelete ) ; } ) ; } try { new ExecutorServiceUtils ( ) . gracefulShutdown ( deletionService , Duration . ofDays ( 1 ) ) ; } catch ( final InterruptedException e ) { log . warn ( "Error when deleting files" , e ) ; } }
Delete all the files in parallel