public ShardingExecutorService(final int executorSize, final String nameFormat) { executorService = MoreExecutors.listeningDecorator(getExecutorService(executorSize, nameFormat)); MoreExecutors.addDelayedShutdownHook(executorService, 60, TimeUnit.SECONDS); }
public ExecutorEngine(final int executorSize) { executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor( executorSize, executorSize, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingJDBC-%d").build())); MoreExecutors.addDelayedShutdownHook(executorService, 60, TimeUnit.SECONDS); }
public ExecutorEngine(final int executorSize) { executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor( executorSize, executorSize, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingJDBC-%d").build())); MoreExecutors.addDelayedShutdownHook(executorService, 60, TimeUnit.SECONDS); }
public static ExecutorService registerNewExecutorService(final int threadNum, final long terminationTimeout, final TimeUnit timeUnit) { ExecutorService executorService = Executors.newFixedThreadPool(threadNum); MoreExecutors.addDelayedShutdownHook(executorService, terminationTimeout, timeUnit); SquirrelSingletonProvider.getInstance().register(ExecutorService.class, executorService); return executorService; }
public static ScheduledExecutorService registerNewSchedulerService(final int threadNum, final long terminationTimeout, final TimeUnit timeUnit) { ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(threadNum); MoreExecutors.addDelayedShutdownHook(scheduler, terminationTimeout, timeUnit); SquirrelSingletonProvider.getInstance().register(ScheduledExecutorService.class, scheduler); return scheduler; }
/** * Converts the given ThreadPoolExecutor into an ExecutorService that exits * when the application is complete. It does so by using daemon threads and * adding a shutdown hook to wait for their completion. * * <p>This is mainly for fixed thread pools. * See {@link Executors#newFixedThreadPool(int)}. * * @param executor the executor to modify to make sure it exits when the * application is finished * @param terminationTimeout how long to wait for the executor to * finish before terminating the JVM * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ @Beta public static ExecutorService getExitingExecutorService( ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); ExecutorService service = Executors.unconfigurableExecutorService(executor); addDelayedShutdownHook(service, terminationTimeout, timeUnit); return service; }
/** * Converts the given ThreadPoolExecutor into an ExecutorService that exits * when the application is complete. It does so by using daemon threads and * adding a shutdown hook to wait for their completion. * * <p>This is mainly for fixed thread pools. * See {@link Executors#newFixedThreadPool(int)}. * * @param executor the executor to modify to make sure it exits when the * application is finished * @param terminationTimeout how long to wait for the executor to * finish before terminating the JVM * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ public static ExecutorService getExitingExecutorService( ThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); ExecutorService service = Executors.unconfigurableExecutorService(executor); addDelayedShutdownHook(service, terminationTimeout, timeUnit); return service; }
/** * Converts the given ScheduledThreadPoolExecutor into a * ScheduledExecutorService that exits when the application is complete. It * does so by using daemon threads and adding a shutdown hook to wait for * their completion. * * <p>This is mainly for fixed thread pools. * See {@link Executors#newScheduledThreadPool(int)}. * * @param executor the executor to modify to make sure it exits when the * application is finished * @param terminationTimeout how long to wait for the executor to * finish before terminating the JVM * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ @Beta public static ScheduledExecutorService getExitingScheduledExecutorService( ScheduledThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); ScheduledExecutorService service = Executors.unconfigurableScheduledExecutorService(executor); addDelayedShutdownHook(service, terminationTimeout, timeUnit); return service; }
/** * Converts the given ScheduledThreadPoolExecutor into a * ScheduledExecutorService that exits when the application is complete. It * does so by using daemon threads and adding a shutdown hook to wait for * their completion. * * <p>This is mainly for fixed thread pools. * See {@link Executors#newScheduledThreadPool(int)}. * * @param executor the executor to modify to make sure it exits when the * application is finished * @param terminationTimeout how long to wait for the executor to * finish before terminating the JVM * @param timeUnit unit of time for the time parameter * @return an unmodifiable version of the input which will not hang the JVM */ public static ScheduledExecutorService getExitingScheduledExecutorService( ScheduledThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit) { executor.setThreadFactory(new ThreadFactoryBuilder() .setDaemon(true) .setThreadFactory(executor.getThreadFactory()) .build()); ScheduledExecutorService service = Executors.unconfigurableScheduledExecutorService(executor); addDelayedShutdownHook(service, terminationTimeout, timeUnit); return service; }