List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor
public ScheduledThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler)
From source file:com.espertech.esper.timer.TimerServiceImpl.java
private void getScheduledThreadPoolExecutorDaemonThread() { timer = new ScheduledThreadPoolExecutor(1, new ThreadFactory() { // set new thread as daemon thread and name appropriately public Thread newThread(Runnable r) { String uri = engineURI; if (engineURI == null) { uri = "default"; }//w w w . j a v a 2 s . co m Thread t = new Thread(r, "com.espertech.esper.Timer-" + uri + "-" + id); t.setDaemon(true); return t; } }); timer.setMaximumPoolSize(timer.getCorePoolSize()); timer.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); timer.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); }
From source file:com.thinkbiganalytics.spark.shell.AbstractProcessManager.java
/** * Constructs an {@code AbstractProcessManager} with the specified configuration. * * @param sparkShellProperties the Kylo Spark Shell client configuration * @param kerberosProperties the Kerberos configuration for the Kylo Spark Shell client * @param users the username to password mapping *///from w w w . j ava 2s . c om public AbstractProcessManager(@Nonnull final SparkShellProperties sparkShellProperties, @Nonnull final KerberosSparkProperties kerberosProperties, @Nonnull final Properties users) { this.clientProperties = sparkShellProperties; this.users = users; // Verify Kerberos properties if (kerberosProperties.isKerberosEnabled()) { Preconditions.checkState(StringUtils.isNoneBlank(kerberosProperties.getKeytabLocation()), "The kerberos.spark.keytabLocation property cannot be blank when Kerberos is enabled."); Preconditions.checkState(StringUtils.isNoneBlank(kerberosProperties.getKerberosPrincipal()), "The kerberos.spark.kerberosPrincipal property cannot be blank when Kerberos is enabled."); kerberos = kerberosProperties; } else { kerberos = null; } // Create the scheduler final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("spark-shell-pool-%d").build(); executor = new ScheduledThreadPoolExecutor(1, threadFactory); }
From source file:org.apache.hadoop.mapreduce.v2.hs.JobHistory.java
@Override protected void serviceStart() throws Exception { hsManager.start();//from www.j av a2 s. c o m if (storage instanceof Service) { ((Service) storage).start(); } scheduledExecutor = new ScheduledThreadPoolExecutor(2, new ThreadFactoryBuilder().setNameFormat("Log Scanner/Cleaner #%d").build()); scheduledExecutor.scheduleAtFixedRate(new MoveIntermediateToDoneRunnable(), moveThreadInterval, moveThreadInterval, TimeUnit.MILLISECONDS); // Start historyCleaner scheduleHistoryCleaner(); super.serviceStart(); }
From source file:backtype.storm.localizer.Localizer.java
public void startCleaner() { _cacheCleanupService = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("Localizer Cache Cleanup").build()); _cacheCleanupService.scheduleWithFixedDelay(new Runnable() { @Override/*w w w . j a v a 2 s .com*/ public void run() { handleCacheCleanup(); } }, _cacheCleanupPeriod, _cacheCleanupPeriod, TimeUnit.MILLISECONDS); }
From source file:org.apache.hadoop.hbase.ChoreService.java
/** * @param coreThreadPoolPrefix Prefix that will be applied to the Thread name of all threads * spawned by this service/*w ww . ja v a 2 s . c o m*/ * @param corePoolSize The initial size to set the core pool of the ScheduledThreadPoolExecutor * to during initialization. The default size is 1, but specifying a larger size may be * beneficial if you know that 1 thread will not be enough. */ public ChoreService(final String coreThreadPoolPrefix, int corePoolSize) { this.coreThreadPoolPrefix = coreThreadPoolPrefix; if (corePoolSize < MIN_CORE_POOL_SIZE) corePoolSize = MIN_CORE_POOL_SIZE; final ThreadFactory threadFactory = new ChoreServiceThreadFactory(coreThreadPoolPrefix); scheduler = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory); scheduler.setRemoveOnCancelPolicy(true); scheduledChores = new HashMap<ScheduledChore, ScheduledFuture<?>>(); choresMissingStartTime = new HashMap<ScheduledChore, Boolean>(); }
From source file:net.dv8tion.jda.core.entities.impl.JDAImpl.java
public JDAImpl(AccountType accountType, OkHttpClient.Builder httpClientBuilder, WebSocketFactory wsFactory, boolean autoReconnect, boolean audioEnabled, boolean useShutdownHook, boolean bulkDeleteSplittingEnabled, int corePoolSize, int maxReconnectDelay) { this.accountType = accountType; this.httpClientBuilder = httpClientBuilder; this.wsFactory = wsFactory; this.autoReconnect = autoReconnect; this.audioEnabled = audioEnabled; this.shutdownHook = useShutdownHook ? new Thread(this::shutdown, "JDA Shutdown Hook") : null; this.bulkDeleteSplittingEnabled = bulkDeleteSplittingEnabled; this.pool = new ScheduledThreadPoolExecutor(corePoolSize, new JDAThreadFactory()); this.maxReconnectDelay = maxReconnectDelay; this.presence = new PresenceImpl(this); this.requester = new Requester(this); this.jdaClient = accountType == AccountType.CLIENT ? new JDAClientImpl(this) : null; this.jdaBot = accountType == AccountType.BOT ? new JDABotImpl(this) : null; }
From source file:org.rhq.core.pc.content.ContentManager.java
public void initialize() { log.info("Initializing Content Manager..."); // Determine discovery mode - we only enable discovery if we are inside the agent and the period is positive non-zero this.scheduledDiscoveriesEnabled = (configuration.getContentDiscoveryPeriod() > 0); // Create thread pool executor. Used in both scheduled and non-scheduled mode for all discoveries. int threadPoolSize = configuration.getContentDiscoveryThreadPoolSize(); discoveryThreadPoolExecutor = new ScheduledThreadPoolExecutor(threadPoolSize, new LoggingThreadFactory("Content.discovery", true)); discoveryThreadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); discoveryThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); crudExecutor = new ThreadPoolExecutor(1, 5, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10000), new LoggingThreadFactory("Content.crud", true)); // When running in scheduled mode, create and schedule the thread pool for discovering content if (scheduledDiscoveriesEnabled) { log.info("Initializing scheduled content discovery..."); // Without specifying a particular piece of work, this runner will request the next piece of work from // the scheduled items queue ContentDiscoveryRunner runner = new ContentDiscoveryRunner(this); // Begin the automatic discovery thread long initialDelay = configuration.getContentDiscoveryInitialDelay(); long discoveryPeriod = configuration.getContentDiscoveryPeriod(); discoveryThreadPoolExecutor.scheduleAtFixedRate(runner, initialDelay, discoveryPeriod, TimeUnit.SECONDS); // Add inventory event listener so we can keep the scheduled discoveries consistent with the resources inventoryEventListener = new ContentInventoryEventListener(); // the inventory manager has probably already activated some resources, so let's prepopulate our schedules InventoryManager im = PluginContainer.getInstance().getInventoryManager(); im.notifyForAllActivatedResources(inventoryEventListener); // now ask that the inventory manager tell us about resources that will be activated in the future im.addInventoryEventListener(inventoryEventListener); }// w ww. jav a2 s .c o m log.info("Content Manager initialized..."); }
From source file:org.hyperic.hq.agent.server.session.AgentSynchronizer.java
@PostConstruct void initialize() { this.executor = new ScheduledThreadPoolExecutor(NUM_WORKERS, new ThreadFactory() { private final AtomicLong i = new AtomicLong(0); public Thread newThread(Runnable r) { return new Thread(r, "AgentSynchronizer" + i.getAndIncrement()); }// w ww.j a v a2s. c om }); log.info("starting AgentSynchronizer with " + NUM_WORKERS + " threads"); for (int i = 0; i < NUM_WORKERS; i++) { SchedulerThread worker = new SchedulerThread("AgentSynchronizer" + i, i * 1000); executor.scheduleWithFixedDelay(worker, i + 1, NUM_WORKERS, TimeUnit.SECONDS); } concurrentStatsCollector.register(ConcurrentStatsCollector.AGENT_SYNC_JOB_QUEUE_ADDS); concurrentStatsCollector.register(new StatCollector() { public long getVal() throws StatUnreachableException { synchronized (agentJobs) { return agentJobs.size(); } } public String getId() { return ConcurrentStatsCollector.AGENT_SYNCHRONIZER_QUEUE_SIZE; } }); }
From source file:org.rhq.core.pc.measurement.MeasurementManager.java
public void initialize() { if (configuration.isStartManagementBean()) { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try {/*from w w w . ja v a2s . co m*/ server.registerMBean(this, new ObjectName(OBJECT_NAME)); } catch (JMException e) { LOG.error("Unable to register MeasurementManagerMBean", e); } } this.inventoryManager = PluginContainer.getInstance().getInventoryManager(); int threadPoolSize = configuration.getMeasurementCollectionThreadPoolSize(); long collectionInitialDelaySecs = configuration.getMeasurementCollectionInitialDelay(); if (configuration.isInsideAgent()) { this.collectorThreadPool = new ScheduledThreadPoolExecutor(threadPoolSize, new LoggingThreadFactory(COLLECTOR_THREAD_POOL_NAME, true)); this.senderThreadPool = new ScheduledThreadPoolExecutor(2, new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true)); this.measurementSenderRunner = new MeasurementSenderRunner(this); this.measurementCollectorRunner = new MeasurementCollectorRunner(this); // Schedule the measurement sender to send measurement reports periodically. this.senderThreadPool.scheduleAtFixedRate(measurementSenderRunner, collectionInitialDelaySecs, 30, TimeUnit.SECONDS); // Schedule the measurement collector to collect metrics periodically, whenever there are one or more // metrics due to be collected. this.collectorThreadPool.schedule(new MeasurementCollectionRequester(), collectionInitialDelaySecs, TimeUnit.SECONDS); // Load persistent measurement schedules from the InventoryManager and reconstitute them. Resource platform = PluginContainer.getInstance().getInventoryManager().getPlatform(); reschedule(platform); } }
From source file:org.helios.redis.ts.controller.conn.RedisConnectionManager.java
/** * Creates a new RedisConnectionManager/*from www .ja v a 2 s . c o m*/ * @param configProps The redis-ts.config specified properties */ public RedisConnectionManager(Properties configProps) { reconnectPeriod = Integer.parseInt(configProps.getProperty("redis.reconnect.period", "5")); heartbeatPeriod = Integer.parseInt(configProps.getProperty("redis.heartbeat.period", "3")); heartbeatPublishPeriod = Integer.parseInt(configProps.getProperty("redis.heartbeat.period.publish", "2")); int poolSize = Integer.parseInt(configProps.getProperty("redis.scheduler.pool.size", "5")); scheduler = new ScheduledThreadPoolExecutor(poolSize, threadFactory); ThreadPoolMonitor.registerMonitor(scheduler, new StringBuilder(getClass().getPackage().getName()) .append(":service=Scheduler,name=RedisConnectionManager")); scheduler.prestartCoreThread(); initPoolConfig(configProps); host = configProps.getProperty("redis.connect.host"); auth = configProps.getProperty("redis.connect.auth"); port = Integer.parseInt(configProps.getProperty("redis.connect.port", "6379")); timeout = Integer.parseInt(configProps.getProperty("redis.connect.timeout", "2000")); heartbeatChannel = configProps.getProperty("redis.ts.hearbeat.channel", "redis-ts.heartbeat"); log = Logger.getLogger(getClass().getName() + "-" + host + ":" + port); heartbeatPubSub = OptimizedPubSub.getInstance(host, port, auth, timeout); if (auth == null || auth.trim().isEmpty()) { jedisPool = new JedisPool(poolConfig, host, port, timeout); } else { jedisPool = new JedisPool(poolConfig, host, port, timeout, auth); } }