当前位置: 首页>>代码示例>>Java>>正文


Java Executors.newScheduledThreadPool方法代码示例

本文整理汇总了Java中java.util.concurrent.Executors.newScheduledThreadPool方法的典型用法代码示例。如果您正苦于以下问题:Java Executors.newScheduledThreadPool方法的具体用法?Java Executors.newScheduledThreadPool怎么用?Java Executors.newScheduledThreadPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.Executors的用法示例。


在下文中一共展示了Executors.newScheduledThreadPool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ZKNodeWatcher

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 *
 * @param zkMonitorListener a {@link ZKMonitorCallback} instance
 * @param zkNodeAddress Zookeeper server address
 * @param zkNodePollingDelay  Amount of time in ms to poll zookeeper node
 * @param zkNodePollingInitialDelay Amount of initial time in ms before starting poll
 */
public ZKNodeWatcher(final ZKMonitorCallback zkMonitorListener,
                     final InetSocketAddress zkNodeAddress,
                     final int zkNodePollingDelay,
                     final int zkNodePollingInitialDelay) {

    validateArguments(zkMonitorListener,
            zkNodeAddress,
            zkNodePollingDelay,
            zkNodePollingInitialDelay);

    this.zkNodeAddress = zkNodeAddress;
    this.zkMonitorListener = zkMonitorListener;
    this.zkNodePollingDelay = zkNodePollingDelay;
    this.zkNodePollingInitialDelay = zkNodePollingInitialDelay;
    this.executor = Executors.newScheduledThreadPool(1);

}
 
开发者ID:mcafee,项目名称:management-sdk-for-kafka,代码行数:25,代码来源:ZKNodeWatcher.java

示例2: fixedDelay

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private static void fixedDelay() {
  ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

  Runnable task = () -> {
    try {
      System.out.println("Scheduling: " + System.nanoTime());
      TimeUnit.SECONDS.sleep(2);
      System.out.println("Ready:      " +  System.nanoTime());
    }
    catch (InterruptedException e) {
      System.err.println("task interrupted");
    }
  };

  executor.scheduleWithFixedDelay(task, 0, 4, TimeUnit.SECONDS);
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:17,代码来源:TestTest.java

示例3: postConstruct

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@PostConstruct
private void postConstruct() {

  allEnvs = portalConfig.portalSupportedEnvs();

  for (Env env : allEnvs) {
    envStatusMark.put(env, true);
  }

  ScheduledExecutorService
      healthCheckService =
      Executors.newScheduledThreadPool(1, ApolloThreadFactory.create("EnvHealthChecker", false));

  healthCheckService
      .scheduleWithFixedDelay(new HealthCheckTask(applicationContext), 1000, HEALTH_CHECK_INTERVAL,
                              TimeUnit.MILLISECONDS);

}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:19,代码来源:PortalSettings.java

示例4: initCollectionTimer

import java.util.concurrent.Executors; //导入方法依赖的package包/类
/**
 * 
 */
private void initCollectionTimer() {
    statScheduler = Executors.newScheduledThreadPool(1);
    statScheduler.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            lock.lock();
            try {
                //抓取kafka消费组信息
                fetchConsumerGroupFromKafkaAndZK();
                fetchProducerStatFromZK();
            } finally {
                lock.unlock();
            }
        }
    }, 1, 5, TimeUnit.SECONDS);
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:20,代码来源:KafkaMonitor.java

示例5: main

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public static void main(String[] args) {
    final LoadMonitor monitor = new LoadMonitor(null);
    final ScheduledExecutorService scheduler =
        Executors.newScheduledThreadPool(1);
    final ScheduledFuture<?> monitorTask =
        monitor.startMonitoring(scheduler);
    final ScheduledFuture<?> printTask =
        monitor.printMonitoring(scheduler);

    // Run the tasks for 2 minutes
    scheduler.schedule(
        new Runnable() {
            public void run() {
                monitorTask.cancel(true);
                printTask.cancel(true);
            }
        }, 5*60, TimeUnit.SECONDS);
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:19,代码来源:LoadMonitor.java

示例6: CachedWorkerPool

import java.util.concurrent.Executors; //导入方法依赖的package包/类
CachedWorkerPool(long keepAliveTime, TimeUnit unit) {
    this.keepAliveTime = unit != null ? unit.toNanos(keepAliveTime) : 0;
    this.expiringWorkerQueue = new ConcurrentLinkedQueue();
    this.allWorkers = new CompositeSubscription();
    ScheduledExecutorService evictor = null;
    Future<?> task = null;
    if (unit != null) {
        evictor = Executors.newScheduledThreadPool(1, CachedThreadScheduler.EVICTOR_THREAD_FACTORY);
        NewThreadWorker.tryEnableCancelPolicy(evictor);
        task = evictor.scheduleWithFixedDelay(new Runnable() {
            public void run() {
                CachedWorkerPool.this.evictExpiredWorkers();
            }
        }, this.keepAliveTime, this.keepAliveTime, TimeUnit.NANOSECONDS);
    }
    this.evictorService = evictor;
    this.evictorTask = task;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:19,代码来源:CachedThreadScheduler.java

示例7: MemStoreChunkPool

import java.util.concurrent.Executors; //导入方法依赖的package包/类
MemStoreChunkPool(Configuration conf, int chunkSize, int maxCount,
    int initialCount) {
  this.maxCount = maxCount;
  this.chunkSize = chunkSize;
  this.reclaimedChunks = new LinkedBlockingQueue<Chunk>();
  for (int i = 0; i < initialCount; i++) {
    Chunk chunk = new Chunk(chunkSize);
    chunk.init();
    reclaimedChunks.add(chunk);
  }
  final String n = Thread.currentThread().getName();
  scheduleThreadPool = Executors.newScheduledThreadPool(1,
      new ThreadFactoryBuilder().setNameFormat(n+"-MemStoreChunkPool Statistics")
          .setDaemon(true).build());
  this.scheduleThreadPool.scheduleAtFixedRate(new StatisticsThread(this),
      statThreadPeriod, statThreadPeriod, TimeUnit.SECONDS);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:MemStoreChunkPool.java

示例8: demo

import java.util.concurrent.Executors; //导入方法依赖的package包/类
static void demo() {
	ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
	// 延迟3秒执行
	scheduledThreadPool.schedule(new Runnable() {
		public void run() {
			System.out.println("delay 3 seconds");
		}
	}, 3, TimeUnit.SECONDS);

	// 表示延迟1秒后每3秒执行一次
	scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
		public void run() {
			System.out.println("delay 1 seconds, and excute every 3 seconds");
		}
	}, 1, 3, TimeUnit.SECONDS);
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:17,代码来源:ExecutorsDemo.java

示例9: test2

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private static void test2() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    Runnable task = () -> System.out.println("Scheduling: " + System.nanoTime());
    int initialDelay = 0;
    int period = 1;
    executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
}
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:8,代码来源:Executors3.java

示例10: initialize

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public void initialize() {

    api.registerforChangeEvents(this);
    ScheduledExecutorService executerPool = Executors.newScheduledThreadPool(1);
    executerPool.schedule(new InitializationRunnable(), 3, TimeUnit.SECONDS);
    updateStatus(ThingStatus.ONLINE);
    super.initialize();

}
 
开发者ID:Wire82,项目名称:org.openhab.binding.heos,代码行数:11,代码来源:HeosPlayerHandler.java

示例11: scheduleWithFixedDelay

import java.util.concurrent.Executors; //导入方法依赖的package包/类
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay,
                                                 long delay, TimeUnit unit) {
    if (ses == null)
        ses = Executors.newScheduledThreadPool(1);
    try {
        return ses.scheduleWithFixedDelay(command, initialDelay, delay, unit);
    } catch (Exception e) {
        return new MockFuture<Object>(new ExecutionException(e));
    }
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:12,代码来源:MockScheduledExecutor.java

示例12: IOSScheduledExecutorPool

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private IOSScheduledExecutorPool() {
    executorService = Executors.newScheduledThreadPool(1, THREAD_FACTORY);
}
 
开发者ID:SnowdogApps,项目名称:MoeSampleApp,代码行数:4,代码来源:HandlerThreadScheduler.java

示例13: initScheduleSync

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public void initScheduleSync()
{
    // every 15 minutes create a thread to check for schedules to sync
    ScheduledExecutorService syncScheduler = Executors.newScheduledThreadPool(1);
    syncScheduler.scheduleAtFixedRate( new ScheduleSyncer(), 60*15, 60*15, TimeUnit.SECONDS );
}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:7,代码来源:ScheduleManager.java

示例14: ScheduledNotifier

import java.util.concurrent.Executors; //导入方法依赖的package包/类
private ScheduledNotifier() {
    _pool = Executors.newScheduledThreadPool(1);
    init();
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:5,代码来源:ScheduledNotifier.java

示例15: init

import java.util.concurrent.Executors; //导入方法依赖的package包/类
public void init() {
	executor = Executors.newScheduledThreadPool(1);
	future = executor.scheduleAtFixedRate(new TcpHeartBeat(this), keepAliveSeconds, keepAliveSeconds,
			TimeUnit.SECONDS);
	connect();
}
 
开发者ID:magcode,项目名称:sunricher-wifi-mqtt,代码行数:7,代码来源:TcpClient.java


注:本文中的java.util.concurrent.Executors.newScheduledThreadPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。