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


Java ScheduledThreadPoolExecutor.scheduleAtFixedRate方法代码示例

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


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

示例1: startComponentLoader

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * Start the configured component loader
 *
 * @throws AgentException
 *             on error 
 */
private void startComponentLoader() throws AgentException {

    ComponentRepository componentRepository = ComponentRepository.getInstance();
    ConfigurationSettings settings = ConfigurationSettings.getInstance();

    log.info("Loading Agent component libraries from '" + settings.getComponentsFolder() + "'");

    // the default loader is the dynamic loader for hot deployment
    DynamicComponentLoader componentLoader = new DynamicComponentLoader(new File(settings.getComponentsFolder()),
                                                                        loadingMutex);

    log.info("Starting hot deployment thread");

    componentMonitor = new ScheduledThreadPoolExecutor(1);
    scheduledFuture = componentMonitor.scheduleAtFixedRate(new ComponentHotDeployTask(componentLoader,
                                                                                      componentRepository),
                                                           settings.getMonitorInitialDelay(),
                                                           settings.getMonitorPollInterval(),
                                                           TimeUnit.SECONDS);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:27,代码来源:MainComponentLoader.java

示例2: init

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@PostConstruct
    public void init() {

        scheduledExecutorService = new ScheduledThreadPoolExecutor(1,
                new BasicThreadFactory.Builder().namingPattern("SendNodeServerInfo-schedule-pool-%d").daemon(true).build());
        scheduledExecutorService.scheduleAtFixedRate(() ->
                {
                    //将负载加载到ZK中
                    if (!CollectionUtils.isEmpty(dataCenterChannelStore.getAllChannels())) {
                        dataCenterChannelStore.getAllChannels().stream().forEach(e -> {
                            log.info("channel id:{}, {}", e.id(), e);
                        });
                    }
                    applicationEventPublisher.publishEvent(
                            NodeServerInfoEvent.builder()
                                    .name(goPushNodeServerConfig.getName())
                                    .nodeServerInfo(watch())
                                    .build());
//                写入zk 其实不需要发送 NodeInfoReq
                    nodeSender.send(NodeInfoReq.builder().build());
                }
                , delay, delay, TimeUnit.MILLISECONDS);

    }
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:25,代码来源:NodeServerInfoWatchdog.java

示例3: afterPropertiesSet

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
    scheduler = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("Otter-Statistics-Table"),
                                                new ThreadPoolExecutor.CallerRunsPolicy());
    if (statUnit > 0) {
        scheduler.scheduleAtFixedRate(new Runnable() {

            public void run() {
                try {
                    flushBehaviorHistory();
                } catch (Exception e) {
                    logger.error("flush delay stat failed!", e);
                }
            }
        }, statUnit, statUnit, TimeUnit.MILLISECONDS);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:17,代码来源:TableStatServiceImpl.java

示例4: serviceStart

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@Override
protected void serviceStart() throws Exception {
  hsManager.start();
  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();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:JobHistory.java

示例5: testFixedRateSequence

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * scheduleAtFixedRate executes series of tasks at given rate.
 * Eventually, it must hold that:
 *   cycles - 1 <= elapsedMillis/delay < cycles
 */
public void testFixedRateSequence() throws InterruptedException {
    final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    try (PoolCleaner cleaner = cleaner(p)) {
        for (int delay = 1; delay <= LONG_DELAY_MS; delay *= 3) {
            final long startTime = System.nanoTime();
            final int cycles = 8;
            final CountDownLatch done = new CountDownLatch(cycles);
            final Runnable task = new CheckedRunnable() {
                public void realRun() { done.countDown(); }};
            final ScheduledFuture periodicTask =
                p.scheduleAtFixedRate(task, 0, delay, MILLISECONDS);
            final int totalDelayMillis = (cycles - 1) * delay;
            await(done, totalDelayMillis + LONG_DELAY_MS);
            periodicTask.cancel(true);
            final long elapsedMillis = millisElapsedSince(startTime);
            assertTrue(elapsedMillis >= totalDelayMillis);
            if (elapsedMillis <= cycles * delay)
                return;
            // else retry with longer delay
        }
        fail("unexpected execution rate");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:ScheduledExecutorTest.java

示例6: scheduleNow

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void scheduleNow(ScheduledThreadPoolExecutor pool,
                 Runnable r, int how) {
    switch (how) {
    case 0:
        pool.schedule(r, 0, MILLISECONDS);
        break;
    case 1:
        pool.schedule(Executors.callable(r), 0, DAYS);
        break;
    case 2:
        pool.scheduleWithFixedDelay(r, 0, 1000, NANOSECONDS);
        break;
    case 3:
        pool.scheduleAtFixedRate(r, 0, 1000, MILLISECONDS);
        break;
    default:
        fail(String.valueOf(how));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:DelayOverflow.java

示例7: scheduleAtTheEndOfTime

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
void scheduleAtTheEndOfTime(ScheduledThreadPoolExecutor pool,
                            Runnable r, int how) {
    switch (how) {
    case 0:
        pool.schedule(r, Long.MAX_VALUE, MILLISECONDS);
        break;
    case 1:
        pool.schedule(Executors.callable(r), Long.MAX_VALUE, DAYS);
        break;
    case 2:
        pool.scheduleWithFixedDelay(r, Long.MAX_VALUE, 1000, NANOSECONDS);
        break;
    case 3:
        pool.scheduleAtFixedRate(r, Long.MAX_VALUE, 1000, MILLISECONDS);
        break;
    default:
        fail(String.valueOf(how));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:DelayOverflow.java

示例8: main

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public static void main(String[] args)
{
    ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(
            10);
    Runnable event = new Runnable()
    {

        @Override
        public void run()
        {
            System.out.println("吃饭,睡觉,打豆豆");

        }
    };
    scheduler.schedule(event, 1, TimeUnit.SECONDS);
    scheduler.scheduleAtFixedRate(event, 5, 1, TimeUnit.SECONDS);
}
 
开发者ID:baohongfei,项目名称:think-in-java,代码行数:18,代码来源:SimpleUsage.java

示例9: init

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@PostConstruct
public void init() {
    scheduledExecutorService = new ScheduledThreadPoolExecutor(1,
            new BasicThreadFactory.Builder().namingPattern("SendDataCenterInfo-schedule-pool-%d").daemon(true).build());
    scheduledExecutorService.scheduleAtFixedRate(() -> applicationEventPublisher.publishEvent(DataCenterInfoEvent.builder()
            .name(goPushDataCenterConfig.getName())
            .dataCenterInfo(watch())
            .build()), delay, delay, TimeUnit.MILLISECONDS);
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:10,代码来源:DataCenterInfoWatchdog.java

示例10: testSchedule4

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
/**
 * scheduleAtFixedRate executes runnable after given initial delay
 */
public void testSchedule4() throws Exception {
    final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1);
    try (PoolCleaner cleaner = cleaner(p)) {
        final long startTime = System.nanoTime();
        final CountDownLatch done = new CountDownLatch(1);
        Runnable task = new CheckedRunnable() {
            public void realRun() {
                done.countDown();
                assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
            }};
        ScheduledFuture f =
            p.scheduleAtFixedRate(task, timeoutMillis(),
                                  LONG_DELAY_MS, MILLISECONDS);
        await(done);
        assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
        f.cancel(true);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ScheduledExecutorTest.java

示例11: realMain

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
static void realMain(String[] args) throws Throwable {
    final int size = 10;
    final ScheduledThreadPoolExecutor pool
        = new ScheduledThreadPoolExecutor(size);
    final Runnable nop = new Runnable() { public void run() {}};

    for (int i = 0; i < size; i++)
        pool.scheduleAtFixedRate(nop, 100L * (i + 1),
                                 1000L, TimeUnit.MILLISECONDS);
    awaitPoolSize(pool, size);
    setCorePoolSize(pool, size - 3);
    setCorePoolSize(pool, size + 3);
    pool.shutdownNow();
    check(pool.awaitTermination(1L, TimeUnit.DAYS));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:ModifyCorePoolSize.java

示例12: startProducer

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public void startProducer(){
    producerExecutorService = new ScheduledThreadPoolExecutor(1);
    producerExecutorService.scheduleAtFixedRate(obdCommandsProducer, 0, 1, TimeUnit.SECONDS);
}
 
开发者ID:kocur,项目名称:Obd2-Tracker,代码行数:5,代码来源:ObdBluetoothService.java

示例13: initMetrics

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void initMetrics() throws Exception {
  metrics = new MetricRegistry();
  // configuration
  metricsOutputDir = conf.get(SLSConfiguration.METRICS_OUTPUT_DIR);
  int metricsWebAddressPort = conf.getInt(
          SLSConfiguration.METRICS_WEB_ADDRESS_PORT,
          SLSConfiguration.METRICS_WEB_ADDRESS_PORT_DEFAULT);
  // create SchedulerMetrics for current scheduler
  String schedulerMetricsType = conf.get(scheduler.getClass().getName());
  Class schedulerMetricsClass = schedulerMetricsType == null?
          defaultSchedulerMetricsMap.get(scheduler.getClass()) :
          Class.forName(schedulerMetricsType);
  schedulerMetrics = (SchedulerMetrics)ReflectionUtils
          .newInstance(schedulerMetricsClass, new Configuration());
  schedulerMetrics.init(scheduler, metrics);

  // register various metrics
  registerJvmMetrics();
  registerClusterResourceMetrics();
  registerContainerAppNumMetrics();
  registerSchedulerMetrics();

  // .csv output
  initMetricsCSVOutput();

  // start web app to provide real-time tracking
  web = new SLSWebApp(this, metricsWebAddressPort);
  web.start();

  // a thread to update histogram timer
  pool = new ScheduledThreadPoolExecutor(2);
  pool.scheduleAtFixedRate(new HistogramsRunnable(), 0, 1000,
          TimeUnit.MILLISECONDS);

  // a thread to output metrics for real-tiem tracking
  pool.scheduleAtFixedRate(new MetricsLogRunnable(), 0, 1000,
          TimeUnit.MILLISECONDS);

  // application running information
  jobRuntimeLogBW = new BufferedWriter(
          new FileWriter(metricsOutputDir + "/jobruntime.csv"));
  jobRuntimeLogBW.write("JobID,real_start_time,real_end_time," +
          "simulate_start_time,simulate_end_time" + EOL);
  jobRuntimeLogBW.flush();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:47,代码来源:ResourceSchedulerWrapper.java

示例14: main

import java.util.concurrent.ScheduledThreadPoolExecutor; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable {

        final CountDownLatch count = new CountDownLatch(1000);

        final ScheduledThreadPoolExecutor pool =
            new ScheduledThreadPoolExecutor(100);
        pool.prestartAllCoreThreads();

        final Runnable incTask = new Runnable() { public void run() {
            count.countDown();
        }};

        pool.scheduleAtFixedRate(incTask, 0, 10, TimeUnit.MILLISECONDS);

        count.await();

        pool.shutdown();
        pool.awaitTermination(1L, TimeUnit.DAYS);
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:Stress.java


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