private void initFlushThread() { flushThreadPool = Executors.newScheduledThreadPool(1); flushThreadPool.scheduleAtFixedRate(new Runnable() { @Override public void run() { flush(); } }, 10, 10, TimeUnit.SECONDS); }
private void scheduleClockUpdating() { ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable, "System Clock"); thread.setDaemon(true); return thread; } }); scheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { now.set(System.currentTimeMillis()); } }, period, period, TimeUnit.MILLISECONDS); }
public void register(TimeUnit timeUnit) { future = threadPool.scheduleAtFixedRate(this, firstTime, frequency, timeUnit); LOG.info("Successfully register timer " + this); }
public ConsulManager(String host, int port) { client = new ConsulClient(host, port); ttlScheduler = new TtlScheduler(client); scheduleRegistry = Executors.newScheduledThreadPool(1, new NamedThreadFactory("retryFailedTtl", true)); scheduleRegistry.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { retryFailedTtl(); } catch (Throwable e) { if (LOGGER.isInfoEnabled()) { LOGGER.info("retry registry znode failed", e); } } } }, ConsulConstants.HEARTBEAT_CIRCLE, ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS); if (LOGGER.isInfoEnabled()) { LOGGER.info("ConsulEcwidClient init finish. client host:" + host + ", port:" + port); } }
private CachedOfflineStateManager() { refresh(); scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("meta-info-offlinestate-refresh-%d").build()); scheduledExecutor.scheduleAtFixedRate(this::refresh, REFRESH_PERIOD_SECONDS, REFRESH_PERIOD_SECONDS, TimeUnit.SECONDS); log.info("CachedOfflineStateManager started"); }
@Override public synchronized void start() { _executor.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { reportMetrics(); } catch (Exception e) { LOG.error(_name + "/KafkaMetricsReporterService failed to report metrics", e); } } }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS); LOG.info("{}/KafkaMetricsReporterService started", _name); }
public ConsulManager(String host, int port) { client = new ConsulClient(host, port); ttlScheduler = new TtlScheduler(client); scheduleRegistry = Executors.newScheduledThreadPool(1, new NamedThreadFactory("retryFailedTtl", true)); scheduleRegistry.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { retryFailedTtl(); } catch (Throwable e) { if (LOGGER.isInfoEnabled()) { LOGGER.info("retry registry znode failed", e); } } } }, ConsulConstants.HEARTBEAT_CIRCLE, ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS); if (LOGGER.isInfoEnabled()) { LOGGER.info("ConsulEcwidClient init finish. client host:" + host + ", port:" + port); } }
@Inject public EventProcessor(ExecutionService executionService, MetadataService metadataService, ActionProcessor actionProcessor, EventQueues eventQueues, JsonUtils jsonUtils, Configuration config) { this.executionService = executionService; this.metadataService = metadataService; this.actionProcessor = actionProcessor; this.eventQueues = eventQueues; this.jsonUtils = jsonUtils; int executorThreadCount = config.getIntProperty("workflow.event.processor.thread.count", 2); if (executorThreadCount > 0) { executorService = Executors.newFixedThreadPool(executorThreadCount); refresh(); Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::refresh, 60, 60, TimeUnit.SECONDS); logger.info("Event Processing is ENABLED. executorThreadCount set to {}", executorThreadCount); } else { logger.warn("Event processing is DISABLED. executorThreadCount set to {}", executorThreadCount); } }
@WebListener public class BackgroundJobManager implements ServletContextListener { private ScheduledExecutorService scheduler; @Override public void contextInitialized(ServletContextEvent event) { scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new SomeDailyJob(), 0, 1, TimeUnit.DAYS); scheduler.scheduleAtFixedRate(new SomeHourlyJob(), 0, 1, TimeUnit.HOURS); scheduler.scheduleAtFixedRate(new SomeQuarterlyJob(), 0, 15, TimeUnit.MINUTES); } @Override public void contextDestroyed(ServletContextEvent event) { scheduler.shutdownNow(); } }
private static void loop(ProgressMonitor progressMonitor, long interval) { final ProgressMonitor monitor = progressMonitor; Runnable runner = new Runnable() { public void run() { try { monitor.exportStats(); } catch (Throwable t) { LOG.error("Progress monitor failed", t); } } }; ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.scheduleAtFixedRate(runner, 0, interval, TimeUnit.SECONDS); }
/** * 启动定时任务. */ public void start(long period, TimeUnit unit) { if (started) { throw new IllegalStateException("Scheduler had been started before"); } executor.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { report(); } catch (Throwable e) { logger.error(e.getMessage(), e); } } }, period, period, unit); started = true; logger.info("metric reporters started."); }
@Override public void start(HiveConf hiveConf) throws Exception { this.hiveConf = hiveConf; HiveTxnManager mgr = TxnManagerFactory.getTxnManagerFactory().getTxnManager(hiveConf); if(!mgr.supportsAcid()) { LOG.info(this.getClass().getName() + " not started since " + mgr.getClass().getName() + " does not support Acid."); return;//there are no transactions in this case } pool = Executors.newScheduledThreadPool(1, new ThreadFactory() { private final AtomicInteger threadCounter = new AtomicInteger(); @Override public Thread newThread(Runnable r) { return new Thread(r, HouseKeeperServiceBase.this.getClass().getName() + "-" + threadCounter.getAndIncrement()); } }); TimeUnit tu = TimeUnit.MILLISECONDS; pool.scheduleAtFixedRate(getScheduedAction(hiveConf, isAliveCounter), getStartDelayMs(), getIntervalMs(), tu); LOG.info("Started " + this.getClass().getName() + " with delay/interval = " + getStartDelayMs() + "/" + getIntervalMs() + " " + tu); }
protected void startReloadThread() { if (this.reloadIntervalSeconds > 0) { this.scheduler = Executors.newSingleThreadScheduledExecutor(); ((ScheduledExecutorService) this.scheduler).scheduleAtFixedRate(this, reloadIntervalSeconds, reloadIntervalSeconds, TimeUnit.SECONDS); } }
static void tryStart(boolean purgeEnabled) { if (purgeEnabled) { for (;;) { ScheduledExecutorService curr = PURGE_THREAD.get(); if (curr != null) { return; } ScheduledExecutorService next = Executors.newScheduledThreadPool(1, new RxThreadFactory("RxSchedulerPurge")); if (PURGE_THREAD.compareAndSet(curr, next)) { next.scheduleAtFixedRate(new ScheduledTask(), PURGE_PERIOD_SECONDS, PURGE_PERIOD_SECONDS, TimeUnit.SECONDS); return; } else { next.shutdownNow(); } } } }
@Override public synchronized void start() { _executor.scheduleAtFixedRate( new Runnable() { @Override public void run() { try { reportMetrics(); } catch (Exception e) { LOG.error(_name + "/StatsdMetricsReporterService failed to report metrics", e); } } }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS ); LOG.info("{}/StatsdMetricsReporterService started", _name); }
@SuppressWarnings("rawtypes") @Ignore("why test JDK feature?") @Test public void testSchedulerPool() throws InterruptedException { logger.info("testSchedulerPool"); ScheduledExecutorService fetchPool = Executors.newScheduledThreadPool(1); final CountDownLatch countDownLatch = new CountDownLatch(3); ScheduledFuture future = fetchPool.scheduleAtFixedRate(new Runnable() { @Override public void run() { countDownLatch.countDown(); } }, 0, 1, TimeUnit.SECONDS); assertTrue("countDownLatch should reach zero in 15 secs", countDownLatch.await(7, TimeUnit.SECONDS)); assertTrue("future should still running", future.cancel(true)); final CountDownLatch countDownLatch2 = new CountDownLatch(3); ScheduledFuture future2 = fetchPool.scheduleAtFixedRate(new Runnable() { @Override public void run() { countDownLatch2.countDown(); throw new RuntimeException(); } }, 0, 1, TimeUnit.SECONDS); assertFalse("countDownLatch2 should NOT reach zero in 15 secs", countDownLatch2.await(7, TimeUnit.SECONDS)); assertFalse("future2 should has been stopped", future2.cancel(true)); }
private ScheduledExecutorService scheduler; public void contextInitialized(ServletContextEvent event) { scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new CleanDBTask(), 0, 1, TimeUnit.HOURS); scheduler.scheduleAtFixedRate(new StatisticsTask(), 0, 15, TimeUnit.MINUTES); } public void contextDestroyed(ServletContextEvent event) { scheduler.shutdownNow(); }
public LocalClient(LocalServer server) { _server = server; _pendingDueToUnregisteredServer = new LinkedBlockingQueue<>(); _pendingFlusher = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread thread = new Thread(runnable); thread.setName("LocalClientFlusher-" + thread.getId()); thread.setDaemon(true); return thread; } }); _pendingFlusher.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { //Ensure messages are flushed even if no more sends are performed flushPending(); } catch (Throwable t) { LOG.error("Uncaught throwable in pending message flusher thread, messages may be lost", t); throw new RuntimeException(t); } } }, 5, 5, TimeUnit.SECONDS); }
@Override public synchronized void start() { _executor.scheduleAtFixedRate( new Runnable() { @Override public void run() { try { reportMetrics(); } catch (Exception e) { LOG.error(_name + "/DefaultMetricsReporterService failed to report metrics", e); } } }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS ); LOG.info("{}/DefaultMetricsReporterService started", _name); }
@WebListener public class BackgroundJobManager implements ServletContextListener { private ScheduledExecutorService scheduler; @Override public void contextInitialized(ServletContextEvent event) { scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new YourParsingJob(), 0, 5, TimeUnit.HOUR); } @Override public void contextDestroyed(ServletContextEvent event) { scheduler.shutdownNow(); } }