List of usage examples for java.util.concurrent Executors newScheduledThreadPool
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory)
From source file:me.bulat.jivr.webmin.consul.service.ConsulServiceImpl.java
@Autowired public ConsulServiceImpl(final ConsulManager consul) { this.consul = consul; this.healthCheck = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override/*w w w. jav a 2 s . co m*/ public Thread newThread(Runnable r) { return new Thread(r, "JIVR-WEB-HEALTH-SERVICE"); } }); }
From source file:org.wso2.carbon.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }/*from w w w . j a v a2s. com*/ log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:org.apache.synapse.commons.throttle.core.ThrottleReplicator.java
public ThrottleReplicator() { String replicatorThreads = System.getProperty("throttling.pool.size"); if (replicatorThreads != null) { replicatorPoolSize = Integer.parseInt(replicatorThreads); }/* w ww . ja va2 s. com*/ log.debug("Replicator pool size set to " + replicatorPoolSize); ScheduledExecutorService executor = Executors.newScheduledThreadPool(replicatorPoolSize, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("Throttle Replicator - " + replicatorCount++); return t; } }); String throttleFrequency = System.getProperty("throttling.replication.frequency"); if (throttleFrequency == null) { throttleFrequency = "50"; } log.debug("Throttling Frequency set to " + throttleFrequency); String maxKeysToReplicate = System.getProperty("throttling.keys.to.replicate"); if (maxKeysToReplicate != null) { keysToReplicate = Integer.parseInt(maxKeysToReplicate); } log.debug("Max keys to Replicate " + keysToReplicate); for (int i = 0; i < replicatorPoolSize; i++) { executor.scheduleAtFixedRate(new ReplicatorTask(), Integer.parseInt(throttleFrequency), Integer.parseInt(throttleFrequency), TimeUnit.MILLISECONDS); } }
From source file:de.uni_koeln.spinfo.maalr.sigar.SigarWrapper.java
private static void initialize() { logger.info("Initializing..."); String libBase = "/hyperic-sigar-1.6.5/sigar-bin/lib/"; try {//from w w w . j a v a2s . co m String prefix = "libsigar"; if (SystemUtils.IS_OS_WINDOWS) { prefix = "sigar"; } String arch = getSystemArch(); String suffix = getSystemSuffix(); String resourceName = prefix + "-" + arch + "-" + suffix; logger.info("Native library: " + resourceName); String resource = libBase + resourceName; URL toLoad = SigarWrapper.class.getResource(resource); File home = new File(System.getProperty("user.home")); File libs = new File(home, ".maalr/libs/sigar"); libs.mkdirs(); File tmp = new File(libs, resourceName); tmp.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tmp); InputStream in = toLoad.openStream(); int i; while ((i = in.read()) != -1) { fos.write(i); } in.close(); fos.close(); logger.info("Library copied to " + tmp.getAbsolutePath()); String oldPath = System.getProperty("java.library.path"); System.setProperty("java.library.path", oldPath + SystemUtils.PATH_SEPARATOR + libs.getAbsolutePath()); logger.info("java.library.path updated: " + System.getProperty("java.library.path")); executors = Executors.newScheduledThreadPool(1, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); logger.info("Initialization completed."); } catch (Exception e) { logger.error("Failed to initialize!", e); } }
From source file:com.seyren.core.service.schedule.CheckScheduler.java
@Inject public CheckScheduler(ChecksStore checksStore, CheckRunnerFactory checkRunnerFactory, SeyrenConfig seyrenConfig) {/*from w w w.ja v a2 s.c om*/ this.checksStore = checksStore; this.checkRunnerFactory = checkRunnerFactory; this.executor = Executors.newScheduledThreadPool(seyrenConfig.getNoOfThreads(), new ThreadFactoryBuilder().setNameFormat("seyren.check-scheduler-%s").setDaemon(false).build()); this.instanceIndex = seyrenConfig.getCheckExecutorInstanceIndex(); this.totalWorkers = seyrenConfig.getCheckExecutorTotalInstances(); this.checkExecutionTimeoutSeconds = seyrenConfig.getMaxCheckExecutionTimeInSeconds(); }
From source file:org.opendaylight.controller.netconf.ssh.osgi.NetconfSSHActivator.java
@Override public void start(final BundleContext bundleContext) throws IOException { minaTimerExecutor = Executors.newScheduledThreadPool(POOL_SIZE, new ThreadFactory() { @Override/* w w w. java 2s .c o m*/ public Thread newThread(final Runnable r) { return new Thread(r, "netconf-ssh-server-mina-timers"); } }); clientGroup = new NioEventLoopGroup(); nioExecutor = ThreadUtils.newFixedThreadPool("netconf-ssh-server-nio-group", POOL_SIZE); server = startSSHServer(bundleContext); }
From source file:io.gravitee.gateway.services.healthcheck.HealthCheckService.java
@Override protected void doStart() throws Exception { super.doStart(); eventManager.subscribeForEvents(this, ReactorEvent.class); executorService = Executors.newScheduledThreadPool(threads, new ThreadFactory() { private int counter = 0; private String prefix = "healthcheck"; public Thread newThread(Runnable r) { return new Thread(r, prefix + '-' + counter++); }//from ww w . ja v a 2 s .c o m }); }
From source file:com.jkoolcloud.tnt4j.utils.TimeService.java
/** * Schedule automatic clock synchronization with NTP and internal clocks * */// ww w. j a va2 s .com private static synchronized void scheduleUpdates() { if (scheduler == null) { scheduler = Executors.newScheduledThreadPool(1, new TimeServiceThreadFactory("TimeService/clock-sync")); clockSyncTask = new ClockDriftMonitorTask(logger); scheduler.submit(clockSyncTask); } }
From source file:org.apache.hadoop.hive.ql.txn.AcidHouseKeeperService.java
@Override public void start(HiveConf hiveConf) throws Exception { HiveTxnManager mgr = TxnManagerFactory.getTxnManagerFactory().getTxnManager(hiveConf); if (!mgr.supportsAcid()) { LOG.info(AcidHouseKeeperService.class.getName() + " not started since " + mgr.getClass().getName() + " does not support Acid."); return;//there are no transactions in this case }//from w w w . j ava 2 s. c o m pool = Executors.newScheduledThreadPool(1, new ThreadFactory() { private final AtomicInteger threadCounter = new AtomicInteger(); @Override public Thread newThread(Runnable r) { return new Thread(r, "DeadTxnReaper-" + threadCounter.getAndIncrement()); } }); TimeUnit tu = TimeUnit.MILLISECONDS; pool.scheduleAtFixedRate(new TimedoutTxnReaper(hiveConf, this), hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_START, tu), hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_INTERVAL, tu), TimeUnit.MILLISECONDS); LOG.info("Started " + this.getClass().getName() + " with delay/interval = " + hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_START, tu) + "/" + hiveConf.getTimeVar(HiveConf.ConfVars.HIVE_TIMEDOUT_TXN_REAPER_INTERVAL, tu) + " " + tu); }
From source file:com.meltmedia.dropwizard.etcd.cluster.ClusterProcessorIT.java
@Before public void setUp() throws Exception { ObjectMapper mapper = new ObjectMapper(); executor = Executors.newScheduledThreadPool(4, Executors.defaultThreadFactory()); lifecycle = mock(ClusterProcessLifecycle.class); service = ClusterProcessor.<NodeData>builder().withMapper(mapper) .withDirectory(factoryRule.getFactory().newDirectory("/jobs", new TypeReference<ClusterProcess>() { })).withLifecycleFactory(d -> lifecycle).withNodeId("1").withType(new TypeReference<NodeData>() { }).build();//from w ww . j av a 2s.com dao = new EtcdDirectoryDao<ClusterProcess>(etcdClientSupplier::getClient, "/test/jobs", mapper, new TypeReference<ClusterProcess>() { }); service.start(); }