List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor
public ScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler)
From source file:devbury.threadscope.ThreadScopePropagatingScheduler.java
@Override protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler) { @Override/*from ww w. java 2 s.co m*/ protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable, RunnableScheduledFuture<V> task) { LOGGER.debug("Decorating Task"); return buildRunnableScheduledFuture(threadScopeManager, task); } @Override protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable, RunnableScheduledFuture<V> task) { return decorateTask((Callable<V>) null, task); } }; }
From source file:com.alibaba.otter.common.push.media.MediaSubscribeManager.java
protected void doInit() { if (executor != null) { return;/*from ww w. j a v a 2 s.c o m*/ } executor = new ScheduledThreadPoolExecutor(poolSize, new NamedThreadFactory("canal-media-callback-worker"), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:be.vlaanderen.sesam.monitor.internal.util.ThreadPoolTaskScheduler.java
/** * Create a new {@link ScheduledExecutorService} instance. * <p>The default implementation creates a {@link ScheduledThreadPoolExecutor}. * Can be overridden in subclasses to provide custom {@link ScheduledExecutorService} instances. * @param poolSize the specified pool size * @param threadFactory the ThreadFactory to use * @param rejectedExecutionHandler the RejectedExecutionHandler to use * @return a new ScheduledExecutorService instance * @see #afterPropertiesSet()/*from ww w .ja v a 2s . c o m*/ * @see java.util.concurrent.ScheduledThreadPoolExecutor */ protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { return new ScheduledThreadPoolExecutor(poolSize, threadFactory, rejectedExecutionHandler); }
From source file:tv.arte.resteventapi.core.scheduling.RestEventScheduledThreadPoolExecutorScheduler.java
/** * @see ScheduledThreadPoolExecutor#ScheduledThreadPoolExecutor(int, ThreadFactory, RejectedExecutionHandler) *//*from www. ja v a 2 s . c o m*/ public RestEventScheduledThreadPoolExecutorScheduler(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler, Integer secondsBetweenRescheduling, Integer maxMinutesToPrefetchScheduledEvents) { if (secondsBetweenRescheduling != null) { if (secondsBetweenRescheduling < 0) { throw new RestEventApiRuntimeException( "secondsBetweenRescheduling should be a positive integer value"); } this.secondsBetweenRescheduling = secondsBetweenRescheduling; } if (maxMinutesToPrefetchScheduledEvents != null) { if (maxMinutesToPrefetchScheduledEvents < 0) { throw new RestEventApiRuntimeException( "maxMinutesToPrefetchScheduledEvents should be a positive integer value"); } this.maxMinutesToPrefetchScheduledEvents = maxMinutesToPrefetchScheduledEvents; } this.reschedulingExecutor = Executors.newSingleThreadScheduledExecutor(threadFactory); this.reschedulingExecutor.scheduleWithFixedDelay(new ReschedulingTask(), 30, this.secondsBetweenRescheduling, TimeUnit.SECONDS); this.restEventsScheduledExecutor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory, handler); }
From source file:uk.co.flax.biosolr.solr.update.processor.OntologyUpdateProcessorFactory.java
private void initialiseOntologyCheckScheduler(SolrCore core) { executor = new ScheduledThreadPoolExecutor(1, new DefaultSolrThreadFactory("ontologyUpdate"), (Runnable r, ThreadPoolExecutor e) -> LOGGER.warn("Skipping execution of '{}' using '{}'", r, e)); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); // Add CloseHook to tidy up if core closes core.addCloseHook(new CloseHook() { @Override// w w w . ja v a 2s .c om public void preClose(SolrCore core) { LOGGER.info("Triggering graceful shutdown of OntologyUpdate executor"); disposeHelper(); executor.shutdown(); } @Override public void postClose(SolrCore core) { if (executor.isTerminating()) { LOGGER.info("Forcing shutdown of OntologyUpdate executor"); executor.shutdownNow(); } } }); if (DELETE_CHECK_DELAY_MS > 0) { executor.scheduleAtFixedRate(new OntologyCheckRunnable(this), DELETE_CHECK_DELAY_MS, DELETE_CHECK_DELAY_MS, TimeUnit.MILLISECONDS); } }
From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java
private TaskExecutor createDefaultShutdownTaskExecutor() { ThreadPoolTaskScheduler taskExecutor = new ThreadPoolTaskScheduler() { private static final long serialVersionUID = 1L; protected ScheduledExecutorService createExecutor(int poolSize, final ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) { ThreadFactory tf = new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = threadFactory.newThread(r); t.setName("Spring DM context shutdown thread"); return t; }/*from w ww . j a va 2 s.com*/ }; return new ScheduledThreadPoolExecutor(poolSize, tf, rejectedExecutionHandler); } }; taskExecutor.afterPropertiesSet(); isShutdownTaskExecutorManagedInternally = true; return taskExecutor; }