use of java.util.concurrent.RejectedExecutionHandler in project spring-framework by spring-projects.
the class ScheduledExecutorFactoryBeanTests method testShutdownIsPropagatedToTheExecutorOnDestroy.
@Test
@SuppressWarnings("serial")
public void testShutdownIsPropagatedToTheExecutorOnDestroy() throws Exception {
final ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
ScheduledExecutorFactoryBean factory = new ScheduledExecutorFactoryBean() {
@Override
protected ScheduledExecutorService createExecutor(int poolSize, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return executor;
}
};
factory.setScheduledExecutorTasks(new ScheduledExecutorTask[] { new NoOpScheduledExecutorTask() });
factory.setWaitForTasksToCompleteOnShutdown(true);
factory.afterPropertiesSet();
factory.destroy();
verify(executor).shutdown();
}
use of java.util.concurrent.RejectedExecutionHandler in project hazelcast by hazelcast.
the class LoggingScheduledExecutorTest method testConstructor_withRejectedExecutionHandler.
@Test
public void testConstructor_withRejectedExecutionHandler() {
RejectedExecutionHandler handler = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
}
};
executor = new LoggingScheduledExecutor(logger, 1, factory, handler);
}
use of java.util.concurrent.RejectedExecutionHandler in project yyl_example by Relucent.
the class ThreadPoolExecutorTest2 method main.
public static void main(String[] args) throws InterruptedException {
int cpu = Runtime.getRuntime().availableProcessors();
ThreadPoolExecutor executor = new //
ThreadPoolExecutor(//
0, //
cpu * 2, //
60, //
TimeUnit.SECONDS, //
new SynchronousQueue<Runnable>(), // 自定义实现,使用当前线程继续执行任务
new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
if (!executor.isShutdown()) {
runnable.run();
}
}
});
for (int i = 0; i < 100; i++) {
executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.sleep(1 * 1000);
System.out.println(Thread.currentThread().getName());
return null;
}
});
}
executor.awaitTermination(1 * 1000 * 100, TimeUnit.SECONDS);
executor.shutdown();
}
use of java.util.concurrent.RejectedExecutionHandler in project apex-core by apache.
the class DefaultApexPluginDispatcher method serviceInit.
@Override
protected void serviceInit(Configuration conf) throws Exception {
super.serviceInit(conf);
LOG.debug("Creating plugin dispatch queue with size {}", qsize);
blockingQueue = new ArrayBlockingQueue<>(qsize);
RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
try {
blockingQueue.remove();
executor.submit(r);
} catch (NoSuchElementException ex) {
// Ignore no-such element as queue may finish, while this handler is called.
}
}
};
executorService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, blockingQueue, new NameableThreadFactory("PluginExecutorThread"), rejectionHandler);
}
use of java.util.concurrent.RejectedExecutionHandler in project lucene-solr by apache.
the class DocExpirationUpdateProcessorFactory method initDeleteExpiredDocsScheduler.
private void initDeleteExpiredDocsScheduler(SolrCore core) {
executor = new ScheduledThreadPoolExecutor(1, new DefaultSolrThreadFactory("autoExpireDocs"), new RejectedExecutionHandler() {
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
log.warn("Skipping execution of '{}' using '{}'", r, e);
}
});
core.addCloseHook(new CloseHook() {
public void postClose(SolrCore core) {
if (executor.isTerminating()) {
log.info("Waiting for close of DocExpiration Executor");
ExecutorUtil.shutdownAndAwaitTermination(executor);
}
}
public void preClose(SolrCore core) {
log.info("Triggering Graceful close of DocExpiration Executor");
executor.shutdown();
}
});
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
// we don't want this firing right away, since the core may not be ready
final long initialDelay = deletePeriodSeconds;
// TODO: should we make initialDelay configurable
// TODO: should we make initialDelay some fraction of the period?
executor.scheduleAtFixedRate(new DeleteExpiredDocsRunnable(this), deletePeriodSeconds, deletePeriodSeconds, TimeUnit.SECONDS);
}
Aggregations