Java Code Examples for com.google.common.util.concurrent.MoreExecutors#addDelayedShutdownHook()
The following examples show how to use
com.google.common.util.concurrent.MoreExecutors#addDelayedShutdownHook() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncSnapshotPersistence.java From opensharding-spi-impl with Apache License 2.0 | 5 votes |
public AsyncSnapshotPersistence(final DataSource dataSource) { this.dataSource = dataSource; COMMITTED_TRANSACTION_ID_BUFFER.add(Lists.<String>newArrayList()); timerExecutor = Executors.newSingleThreadScheduledExecutor(ShardingThreadFactoryBuilder.build("AsyncPersistence")); MoreExecutors.addDelayedShutdownHook(timerExecutor, 30, TimeUnit.SECONDS); timerExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { deleteCommittedSnapshots(); } }, 10, 1000, TimeUnit.MILLISECONDS); }
Example 2
Source File: ExecutorEngine.java From sharding-jdbc-1.5.1 with Apache License 2.0 | 4 votes |
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); }
Example 3
Source File: SagaActuatorFactory.java From opensharding-spi-impl with Apache License 2.0 | 4 votes |
private static ExecutorService createExecutorService(final int executorSize) { ThreadFactory threadFactory = ShardingThreadFactoryBuilder.build("Saga-%d"); ExecutorService result = executorSize > 0 ? Executors.newFixedThreadPool(executorSize, threadFactory) : Executors.newCachedThreadPool(threadFactory); MoreExecutors.addDelayedShutdownHook(result, 60, TimeUnit.SECONDS); return result; }
Example 4
Source File: ShardingSphereExecutorService.java From shardingsphere with Apache License 2.0 | 4 votes |
public ShardingSphereExecutorService(final int executorSize, final String nameFormat) { executorService = MoreExecutors.listeningDecorator(getExecutorService(executorSize, nameFormat)); MoreExecutors.addDelayedShutdownHook(executorService, 60, TimeUnit.SECONDS); }