@Override public void close() throws Exception { CloseableSchedulerThreadPool.close(executor, logger); } };
/** * Creates a new scheduler service. * * The underlying executor uses a {@link ThreadPoolExecutor}, with a given pool size. * * @param corePoolSize -- the <b>maximum</b> number of threads used by the underlying {@link ThreadPoolExecutor} */ public LocalSchedulerService(int corePoolSize) { this(new CloseableSchedulerThreadPool(THREAD_NAME_PREFIX, corePoolSize)); }
/** * schedules a thread that will asynchronously evict expired FragmentHandler from the cache. * First update will be scheduled after refreshDelayMs, and each subsequent update will start after * the previous update finishes + refreshDelayMs * * @param refreshDelayMs delay, in seconds, between successive eviction checks */ private void initEvictionThread(long refreshDelayMs) { scheduler.scheduleWithFixedDelay(new Runnable() { @Override public void run() { for (FragmentHandler handler : handlers.asMap().values()) { try { if (handler.isExpired()) { handlers.invalidate(handler.getHandle()); } } catch (Throwable e) { logger.warn("Failed to evict FragmentHandler for {}", QueryIdHelper.getQueryIdentifier(handler.getHandle()), e); } } } }, refreshDelayMs, refreshDelayMs, TimeUnit.MILLISECONDS); }
private void scheduleNext() { if (cancelled.get()) { return; } Instant instant = nextInstant(); ScheduledFuture<?> future = executorService.schedule(this, ChronoUnit.MILLIS.between(Instant.now(), instant), TimeUnit.MILLISECONDS); currentTask.set(future); }
@Override public void close() throws Exception { if (!closed) { closed = true; logger.info("Stopping ZKClusterClient"); initialConnection.countDown(); // discovery attempts to close its caches(ie serviceCache) already. however, being good citizens we make sure to // explicitly close serviceCache. Not only that we make sure to close serviceCache before discovery to prevent // double releasing and disallowing jvm to spit bothering warnings. simply put, we are great! AutoCloseables.close(discovery, curator, CloseableSchedulerThreadPool.of(executorService, logger)); logger.info("Stopped ZKClusterClient"); } }
/** * Verify that threads created by the thread factory are daemon threads */ @Test public void newThread() { LocalSchedulerService service = new LocalSchedulerService(1); final Runnable runnable = mock(Runnable.class); final Thread thread = service.getExecutorService().getThreadFactory().newThread(runnable); assertTrue("thread should be a daemon thread", thread.isDaemon()); assertTrue("thread name should start with scheduler-", thread.getName().startsWith("scheduler-")); }
}).when(executorService).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
@Override public void close() { CloseableSchedulerThreadPool.close(this, logger); }
}).when(executorService).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
@Override public void close() throws Exception { close(this, logger); }
}).when(executorService).schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
@Override public void close() throws Exception { LOGGER.info("Stopping SchedulerService"); executorService.close(); LOGGER.info("Stopped SchedulerService"); }
/** * Verify that {@code ExecutorService#shutdown()} is called when service is closed */ @Test public void close() throws Exception { final CloseableSchedulerThreadPool executorService = mock(CloseableSchedulerThreadPool.class); final LocalSchedulerService service = new LocalSchedulerService(executorService); service.close(); verify(executorService).close(); }