當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。