use of java.util.concurrent.ScheduledThreadPoolExecutor in project distributedlog by twitter.
the class TestDynamicConfigurationFactory method getConfigFactory.
private DynamicConfigurationFactory getConfigFactory(File configFile) {
String streamConfigPath = configFile.getParent();
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
ConcurrentBaseConfiguration defaultConf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
return new DynamicConfigurationFactory(executorService, 100, TimeUnit.MILLISECONDS);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project distributedlog by twitter.
the class TestStreamManager method testCreateStream.
@Test
public void testCreateStream() throws Exception {
Stream mockStream = mock(Stream.class);
final String streamName = "stream1";
when(mockStream.getStreamName()).thenReturn(streamName);
StreamFactory mockStreamFactory = mock(StreamFactory.class);
StreamPartitionConverter mockPartitionConverter = mock(StreamPartitionConverter.class);
StreamConfigProvider mockStreamConfigProvider = mock(StreamConfigProvider.class);
when(mockStreamFactory.create((String) any(), (DynamicDistributedLogConfiguration) any(), (StreamManager) any())).thenReturn(mockStream);
DistributedLogNamespace dlNamespace = mock(DistributedLogNamespace.class);
ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
StreamManager streamManager = new StreamManagerImpl("", new DistributedLogConfiguration(), executorService, mockStreamFactory, mockPartitionConverter, mockStreamConfigProvider, dlNamespace);
assertTrue(Await.ready(streamManager.createStreamAsync(streamName)).isReturn());
verify(dlNamespace).createLog(streamName);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project jackrabbit-oak by apache.
the class Oak method defaultScheduledExecutor.
/**
* Default {@code ScheduledExecutorService} used for scheduling background tasks.
* This default spawns up to 32 background thread on an as need basis. Idle
* threads are pruned after one minute.
* @return fresh ScheduledExecutorService
*/
public static ScheduledExecutorService defaultScheduledExecutor() {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(32, new ThreadFactory() {
private final AtomicInteger counter = new AtomicInteger();
@Override
public Thread newThread(@Nonnull Runnable r) {
Thread thread = new Thread(r, createName());
thread.setDaemon(true);
return thread;
}
private String createName() {
return "oak-scheduled-executor-" + counter.getAndIncrement();
}
});
executor.setKeepAliveTime(1, TimeUnit.MINUTES);
executor.allowCoreThreadTimeOut(true);
return executor;
}
use of java.util.concurrent.ScheduledThreadPoolExecutor 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);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project logging-log4j2 by apache.
the class ConfigurationScheduler method getExecutorService.
private ScheduledExecutorService getExecutorService() {
if (executorService == null) {
if (scheduledItems > 0) {
LOGGER.debug("{} starting {} threads", SIMPLE_NAME, scheduledItems);
scheduledItems = Math.min(scheduledItems, MAX_SCHEDULED_ITEMS);
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(scheduledItems, Log4jThreadFactory.createDaemonThreadFactory("Scheduled"));
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
this.executorService = executor;
} else {
LOGGER.debug("{}: No scheduled items", SIMPLE_NAME);
}
}
return executorService;
}
Aggregations