use of java.util.concurrent.ScheduledThreadPoolExecutor in project jetty.project by eclipse.
the class WriteFlusherTest method testConcurrent.
@Test
public void testConcurrent() throws Exception {
Random random = new Random();
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(100);
try {
String reason = "THE_CAUSE";
ConcurrentWriteFlusher[] flushers = new ConcurrentWriteFlusher[50000];
FutureCallback[] futures = new FutureCallback[flushers.length];
for (int i = 0; i < flushers.length; ++i) {
int size = 5 + random.nextInt(15);
ByteArrayEndPoint endPoint = new ByteArrayEndPoint(new byte[0], size);
ConcurrentWriteFlusher flusher = new ConcurrentWriteFlusher(endPoint, scheduler, random);
flushers[i] = flusher;
FutureCallback callback = new FutureCallback();
futures[i] = callback;
scheduler.schedule(() -> flusher.onFail(new Throwable(reason)), random.nextInt(75) + 1, TimeUnit.MILLISECONDS);
flusher.write(callback, BufferUtil.toBuffer("How Now Brown Cow."), BufferUtil.toBuffer(" The quick brown fox jumped over the lazy dog!"));
}
int completed = 0;
int failed = 0;
for (int i = 0; i < flushers.length; ++i) {
try {
futures[i].get(15, TimeUnit.SECONDS);
Assert.assertEquals("How Now Brown Cow. The quick brown fox jumped over the lazy dog!", flushers[i].getContent());
completed++;
} catch (ExecutionException x) {
Assert.assertEquals(reason, x.getCause().getMessage());
failed++;
}
}
Assert.assertThat(completed, Matchers.greaterThan(0));
Assert.assertThat(failed, Matchers.greaterThan(0));
Assert.assertEquals(flushers.length, completed + failed);
} finally {
scheduler.shutdown();
}
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project jetty.project by eclipse.
the class ScheduledExecutorScheduler method doStart.
@Override
protected void doStart() throws Exception {
scheduler = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(threadGroup, r, name);
thread.setDaemon(daemon);
thread.setContextClassLoader(classloader);
return thread;
}
});
scheduler.setRemoveOnCancelPolicy(true);
super.doStart();
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project hadoop by apache.
the class EntityGroupFSTimelineStore method serviceStart.
@Override
protected void serviceStart() throws Exception {
super.serviceStart();
LOG.info("Starting {}", getName());
summaryStore.start();
Configuration conf = getConfig();
aclManager = new TimelineACLsManager(conf);
aclManager.setTimelineStore(summaryStore);
summaryTdm = new TimelineDataManager(summaryStore, aclManager);
summaryTdm.init(conf);
addService(summaryTdm);
// start child services that aren't already started
super.serviceStart();
if (!fs.exists(activeRootPath)) {
fs.mkdirs(activeRootPath);
fs.setPermission(activeRootPath, ACTIVE_DIR_PERMISSION);
}
if (!fs.exists(doneRootPath)) {
fs.mkdirs(doneRootPath);
fs.setPermission(doneRootPath, DONE_DIR_PERMISSION);
}
objMapper = new ObjectMapper();
objMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
jsonFactory = new MappingJsonFactory(objMapper);
final long scanIntervalSecs = conf.getLong(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SCAN_INTERVAL_SECONDS, YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_SCAN_INTERVAL_SECONDS_DEFAULT);
final long cleanerIntervalSecs = conf.getLong(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_CLEANER_INTERVAL_SECONDS, YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_CLEANER_INTERVAL_SECONDS_DEFAULT);
final int numThreads = conf.getInt(YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_THREADS, YarnConfiguration.TIMELINE_SERVICE_ENTITYGROUP_FS_STORE_THREADS_DEFAULT);
LOG.info("Scanning active directory {} every {} seconds", activeRootPath, scanIntervalSecs);
LOG.info("Cleaning logs every {} seconds", cleanerIntervalSecs);
executor = new ScheduledThreadPoolExecutor(numThreads, new ThreadFactoryBuilder().setNameFormat("EntityLogPluginWorker #%d").build());
executor.scheduleAtFixedRate(new EntityLogScanner(), 0, scanIntervalSecs, TimeUnit.SECONDS);
executor.scheduleAtFixedRate(new EntityLogCleaner(), cleanerIntervalSecs, cleanerIntervalSecs, TimeUnit.SECONDS);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project hive by apache.
the class DbTxnManager method initHeartbeatExecutorService.
private synchronized void initHeartbeatExecutorService() {
if (heartbeatExecutorService != null && !heartbeatExecutorService.isShutdown() && !heartbeatExecutorService.isTerminated()) {
return;
}
heartbeatExecutorService = Executors.newScheduledThreadPool(conf.getIntVar(HiveConf.ConfVars.HIVE_TXN_HEARTBEAT_THREADPOOL_SIZE), new ThreadFactory() {
private final AtomicInteger threadCounter = new AtomicInteger();
@Override
public Thread newThread(Runnable r) {
return new HeartbeaterThread(r, "Heartbeater-" + threadCounter.getAndIncrement());
}
});
((ScheduledThreadPoolExecutor) heartbeatExecutorService).setRemoveOnCancelPolicy(true);
}
use of java.util.concurrent.ScheduledThreadPoolExecutor in project storm by apache.
the class Localizer method startCleaner.
public void startCleaner() {
_cacheCleanupService = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("Localizer Cache Cleanup").build());
_cacheCleanupService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
handleCacheCleanup();
}
}, _cacheCleanupPeriod, _cacheCleanupPeriod, TimeUnit.MILLISECONDS);
}
Aggregations