List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor
public ScheduledThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler)
From source file:com.ning.metrics.eventtracker.ScribeSender.java
public ScribeSender(ScribeClient scribeClient, int messagesToSendBeforeReconnecting, int maxIdleTimeInMinutes) { this.scribeClient = scribeClient; this.messagesToSendBeforeReconnecting = messagesToSendBeforeReconnecting; // Setup a watchdog for the Scribe connection. We don't want to keep it open forever. For instance, SLB VIP // may trigger a RST if idle more than a few minutes. final ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(1, Executors.defaultThreadFactory()); executor.scheduleAtFixedRate(new Runnable() { @Override/*from w w w . j av a2 s. co m*/ public void run() { if (sleeping.get()) { log.info("Idle connection to Scribe, re-opening it"); createConnection(); } sleeping.set(true); } }, maxIdleTimeInMinutes, maxIdleTimeInMinutes, TimeUnit.MINUTES); }
From source file:io.bitsquare.common.util.Utilities.java
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name, int corePoolSize, int maximumPoolSize, long keepAliveTimeInSec) { final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true) .setPriority(Thread.MIN_PRIORITY).build(); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory); executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS); executor.allowCoreThreadTimeOut(true); executor.setMaximumPoolSize(maximumPoolSize); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); executor.setRejectedExecutionHandler((r, e) -> { log.debug("RejectedExecutionHandler called"); });// w ww.j a v a2 s. c om return executor; }
From source file:io.tilt.minka.business.impl.CoordinatorImpl.java
public CoordinatorImpl(final Config config, final SpectatorSupplier supplier, final ShardID shardId) { super(config, supplier, shardId); this.shardId = shardId; this.executor = new ScheduledThreadPoolExecutor(MAX_CONCURRENT_THREADS, new ThreadFactoryBuilder().setNameFormat(Config.THREAD_NAME_COORDINATOR_IN_BACKGROUND).build()); executor.setRemoveOnCancelPolicy(true); executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); this.rules = new HashMap<>(); getLockingRules().forEach(rule -> this.rules.put(rule.getAction(), rule)); this.futuresBySynchro = new HashMap<>(); this.runnablesBySynchro = new HashMap<>(); this.callablesBySynchro = new HashMap<>(); this.agentsByAction = new HashMap<>(); }
From source file:at.ac.tuwien.infosys.monitoring.HystrixMetricsPoller.java
/** * Allocate resources to begin polling./*from w w w. j a v a 2 s . c o m*/ * <p> * Use <code>start</code> to begin polling. * <p> * Use <code>shutdown</code> to cleanup resources and stop polling. * <p> * Use <code>pause</code> to temporarily stop polling that can be restarted again with <code>start</code>. * * @param listener for callbacks * @param delay */ public HystrixMetricsPoller(MetricsAsJsonPollerListener listener, int delay) { this.listener = listener; executor = new ScheduledThreadPoolExecutor(1, new MetricsPollerThreadFactory()); this.delay = delay; }
From source file:ru.runa.wf.logic.bot.WorkflowThreadPoolBotInvoker.java
/** * Checking botInvokerInvocation.isDone() leads to run() method called only once per moment. *//*from w ww.j a v a 2 s . c o m*/ @Override public synchronized void invokeBots(BotStation botStation, boolean resetFailedDelay) { this.botStation = Delegates.getBotService().getBotStation(botStation.getId()); if (botInvokerInvocation != null && !botInvokerInvocation.isDone()) { log.debug("botInvokerInvocation != null && !botInvokerInvocation.isDone()"); return; } int poolSize = BotStationResources.getThreadPoolSize(); if (executor == null) { log.debug(String.format("Creating new executor(ScheduledExecutorService),size %d", poolSize)); executor = new ScheduledThreadPoolExecutor(poolSize, new BotNamedThreadFactory()); } else { if (executor.getCorePoolSize() != poolSize) { log.debug(String.format("change core thread pool size from %d to %d", executor.getCorePoolSize(), poolSize)); executor.setCorePoolSize(poolSize); } if (executor.getMaximumPoolSize() != poolSize) { log.debug(String.format("change maximum thread pool size from %d to %d", executor.getMaximumPoolSize(), poolSize)); executor.setMaximumPoolSize(poolSize); } } checkStuckBots(); botInvokerInvocation = executor.schedule(this, 1000, TimeUnit.MILLISECONDS); logBotsActivites(); if (resetFailedDelay) { for (WorkflowBotExecutor botExecutor : botExecutors.values()) { botExecutor.resetFailedDelay(); } } }
From source file:com.btoddb.fastpersitentqueue.JournalMgr.java
/** * * @throws IOException//from w w w . j a v a 2 s . co m */ public void init() throws IOException { flushExec = new ScheduledThreadPoolExecutor(numberOfFlushWorkers, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread t = new Thread(runnable); t.setName("FPQ-FSync"); return t; } }); generalExec = Executors.newFixedThreadPool(numberOfGeneralWorkers, new ThreadFactory() { @Override public Thread newThread(Runnable runnable) { Thread t = new Thread(runnable); t.setName("FPQ-GeneralWork"); return t; } }); prepareJournaling(); currentJournalDescriptor = createAndAddNewJournal(); }
From source file:org.rhq.core.pc.event.EventManager.java
public void initialize() { this.activeReport = new EventReport(this.pcConfig.getEventReportMaxPerSource(), this.pcConfig.getEventReportMaxTotal()); // Schedule sender thread(s) to send Event reports to the Server periodically. EventSenderRunner senderRunner = new EventSenderRunner(this); this.senderThreadPool = new ScheduledThreadPoolExecutor(SENDER_THREAD_POOL_CORE_SIZE, new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true)); this.senderThreadPool.scheduleAtFixedRate(senderRunner, this.pcConfig.getEventSenderInitialDelay(), this.pcConfig.getEventSenderPeriod(), TimeUnit.SECONDS); // Set up a thread pool for polling threads. Polling threads will be added to the pool via calls to // registerEventPoller(). this.pollerThreadPool = new ScheduledThreadPoolExecutor(POLLER_THREAD_POOL_CORE_SIZE, new LoggingThreadFactory(POLLER_THREAD_POOL_NAME, true)); this.pollerThreads = new HashMap<PollerKey, Runnable>(); }
From source file:org.rhq.core.pc.configuration.ConfigurationManager.java
public void initialize() { LoggingThreadFactory threadFactory = new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true); threadPool = new ScheduledThreadPoolExecutor(1, threadFactory); ConfigurationCheckExecutor configurationChecker = new ConfigurationCheckExecutor(this, getConfigurationServerService(), PluginContainer.getInstance().getInventoryManager()); if (pluginContainerConfiguration.getConfigurationDiscoveryPeriod() > 0 && pluginContainerConfiguration.isInsideAgent()) { threadPool.scheduleAtFixedRate(configurationChecker, pluginContainerConfiguration.getConfigurationDiscoveryInitialDelay(), pluginContainerConfiguration.getConfigurationDiscoveryPeriod(), TimeUnit.SECONDS); }/*from w w w. j a va 2 s. c om*/ }
From source file:org.energy_home.jemma.javagal.layers.object.WrapperWSNNode.java
public WrapperWSNNode(GalController _gal, final String networkAdd) { gal = _gal;//from w w w .ja v a 2 s . c o m this._numberOfAttempt = 0; this.dead = false; freshnessTPool = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "THPool-Freshness[" + networkAdd + "]"); } }); discoveryTPool = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "THPool-Discovery[" + networkAdd + "]"); } }); forcePingTPool = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { public Thread newThread(Runnable r) { return new Thread(r, "THPool-ForcePing[" + networkAdd + "]"); } }); }