public static ScheduledExecutorService newScheduledThreadPool ( int size , String poolName ) { // Caller runs only occurs after shutdown, as queue size is unbounded. ScheduledThreadPoolExecutor result = new ScheduledThreadPoolExecutor ( size , getThreadFactory ( poolName ) , new CallerRuns ( ) ) ; // Do not execute any periodic tasks after shutdown. result . setContinueExistingPeriodicTasksAfterShutdownPolicy ( false ) ; // Do not execute any delayed tasks after shutdown. result . setExecuteExistingDelayedTasksAfterShutdownPolicy ( false ) ; // Remove tasks from the executor once they are done executing. By default, even when canceled, these tasks are // not removed; if this setting is not enabled we could end up with leaked (and obsolete) tasks. result . setRemoveOnCancelPolicy ( true ) ; return result ; }
Creates a new ScheduledExecutorService that will use daemon threads with appropriate names the threads .