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


Java ScheduledExecutorService.scheduleAtFixedRate方法代码示例

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


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

示例1: main

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public static void main(String[] args) {
     start=System.currentTimeMillis();
     ScheduledExecutorService threadPool=Executors.newScheduledThreadPool(2);
     for (int i=1;i<=5;i++){
         int num=i;
         threadPool.scheduleAtFixedRate(new Runnable() {
             @Override
             public void run() {
                 try {
                     Thread.sleep(50);
                 } catch (InterruptedException e) {
                     e.printStackTrace();
                 }
                 end=System.currentTimeMillis();
                 System.err.println(Thread.currentThread().getName() + "执行任务:"+num+" 间隔时间:"+(end-start)/1000+"秒");
             }

         }, 2, 5, TimeUnit.SECONDS);
         System.out.println("**");

     }

}
 
开发者ID:tomoncle,项目名称:JavaStudy,代码行数:24,代码来源:ThreadPool.java

示例2: test_user

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        final Class clazz = classLoader.loadClass("Issue1488_Server");

        final int THREAD_NUMBER = 10;
        ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(THREAD_NUMBER);
        for (int i = 0; i < 10; ++i) {
            System.out.println("start....");
            threadPool.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    Map map = new HashMap();
                    map.put("run_id", "aeca30e");
                    map.put("port", 1002);
                    map.put("processId", 3001);
                    System.out.println(JSON.toJSONString(JSON.parseObject(JSON.toJSONString(map), clazz)));
                }
            }, 1, 1, TimeUnit.SECONDS);
        }

        Thread.sleep(1000 * 1000);

//
//        Object obj = JSON.parseObject(json, clazz);
//        assertEquals("{\"process_id\":301,\"run_id\":\"aeca30e\"}", JSON.toJSONString(obj));
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Issue1488.java

示例3: init

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public void init(){
	String cleanTime = logCleanTime;
	Date nextExeucteTime = calcNextExecuteTime(cleanTime);
	long initialDelay = nextExeucteTime.getTime() - System.currentTimeMillis();
	
	ScheduledExecutorService executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("CleanLogJob",true));
	executor.scheduleAtFixedRate(new Runnable() {
		@Override
		public void run() {
			try{
				if(master.hasLeaderShip()){
					Calendar instance = Calendar.getInstance();
					instance.add(Calendar.DATE, -logReservedDays);
					LOG.info("START CLEAN EXPIRED TRANSACTION LOGS.DAYS:" + logReservedDays);
					logWritter.cleanFinishedLogs(applicationName, instance.getTime());
					LOG.info("END CLEAN EXPIRED TRANSACTION LOGS.DAYS");
				}else{
					LOG.info("NOT MASTER,do not execute transaction log clean job");
				}
			}catch(Exception e){
				LOG.error("execute clean job error!",e);
			}
		}
	}, initialDelay, 24l*60*60*1000 , TimeUnit.MILLISECONDS);
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:26,代码来源:DataBaseTransactionLogCleanJob.java

示例4: runCheckThread

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
void runCheckThread(){

        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new VIThreadFactory("vi-envIgnite"));
        executorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try{
                    if(waitTimes == 0 || waitTimes >MAXTIMES){

                        if(waitTimes != 0){
                            waitTimes = 0;
                        }
                        EnFactory.getEnApp().register();
                    }
                }
                catch (Throwable e){
                    logger.warn("self registration failed!", e);
                }finally {
                    waitTimes++;
                }

            }
        }, 0, DEFAULTINTERVAL, TimeUnit.SECONDS);
    }
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:25,代码来源:VICoreIgnite.java

示例5: registerPeriodic

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * Registers a periodic task.
 * @param task the task to execute.
 * @param delay the delay to first execution.
 * @param period the period between executions.
 * @param timeout the time to interruption.
 * @param unit the time unit.
 */
private static void registerPeriodic(Runnable task, long delay, long period, long timeout, TimeUnit unit) {
  final ScheduledExecutorService scheduler =
      Executors.newScheduledThreadPool(1);
  final ScheduledFuture<?> handler =
      scheduler.scheduleAtFixedRate(task, delay, period, unit);

  if (timeout > 0) {
    Runnable interrupt = () -> handler.cancel(true);
    scheduler.schedule(interrupt, timeout, TimeUnit.SECONDS);
  }
}
 
开发者ID:braineering,项目名称:ares,代码行数:20,代码来源:RuntimeManager.java

示例6: startCollecting

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public void startCollecting() {
    ScheduledExecutorService executor = executorManager.getExecutor();

    executor.scheduleAtFixedRate(this, 0, config.getReportFrequency(), TimeUnit.MILLISECONDS);
    executor.scheduleAtFixedRate(
        localStatisticsUpdater,
        config.getReportFrequency(),
        config.getReportFrequency(),
        TimeUnit.MILLISECONDS
    );
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:12,代码来源:StatisticsDriver.java

示例7: test2

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的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

示例8: deployContinuously

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
static void deployContinuously(Ignite ignite) {
    long reportFrequency = TestsHelper.getLoadTestsStatisticsReportFrequency();
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    final StatisticsDeploymentHelper helper = new StatisticsDeploymentHelper(ignite);

    executor.scheduleAtFixedRate(new Runnable() {
        @Override public void run() {
            helper.deployStatisticsCollector();
        }
    }, 0, reportFrequency, TimeUnit.MILLISECONDS);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:12,代码来源:Statistics.java

示例9: printMonitoring

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public ScheduledFuture<?> printMonitoring(ScheduledExecutorService ses)
{
    final LoadMonitor mon = this;
    ScheduledFuture<?> monitorTask =
        ses.scheduleAtFixedRate(
            new Runnable() {
                public void run() {
                    System.out.println(mon.getLoad());
                }
            }, LOADMONITOR_SAMPLING_INTERVAL/2,
            LOADMONITOR_SAMPLING_INTERVAL, TimeUnit.MILLISECONDS);
    return monitorTask;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:14,代码来源:LoadMonitor.java

示例10: readPositionEnd

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
@Test
public void readPositionEnd() throws IOException, InterruptedException {
    final Utils.LogFile logFile = new Utils.LogFile(100 * 1024, 400, 100);
    logFile.close();
    final ArrayBlockingQueue<FileChunk> chunkQueue = Queues.newArrayBlockingQueue(1);
    final AsynchronousFileChannel channel = AsynchronousFileChannel.open(logFile.getPath(), StandardOpenOption.READ);
    final CountingAsyncFileChannel spy = new CountingAsyncFileChannel(channel);

    final ChunkReader chunkReader = new ChunkReader(mock(FileInput.class), logFile.getPath(), spy, chunkQueue, 10 * 1024,
            FileInput.InitialReadPosition.END, null);

    final ScheduledExecutorService chunkReaderExecutor = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder()
                    .setDaemon(false)
                    .setNameFormat("file-chunk-reader-%d")
                    .setUncaughtExceptionHandler(this)
                    .build()
    );

    final Thread consumer = new Thread() {
        @Override
        public void run() {
            try {
                final FileChunk chunk = chunkQueue.poll(2, TimeUnit.SECONDS);
                assertNull("Reading from the end of the file must not produce a chunk for a non-changing file.", chunk);
            } catch (InterruptedException ignore) {
            }
        }
    };
    consumer.start();
    chunkReaderExecutor.scheduleAtFixedRate(chunkReader, 0, 250, TimeUnit.MILLISECONDS);
    consumer.join();

    // we can process one chunk at a time, so one read is queued, the second is buffered
    assertEquals("The e should be empty", 1, chunkQueue.remainingCapacity());
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:37,代码来源:ChunkReaderTest.java

示例11: scheduleClockUpdating

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
private void scheduleClockUpdating() {
	ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
		public Thread newThread(Runnable runnable) {
			Thread thread = new Thread(runnable, "System Clock");
			thread.setDaemon(true);
			return thread;
		}
	});
	scheduler.scheduleAtFixedRate(new Runnable() {
		public void run() {
			now.set(System.currentTimeMillis());
		}
	}, period, period, TimeUnit.MILLISECONDS);
}
 
开发者ID:sunzhen086,项目名称:lambo,代码行数:15,代码来源:SystemClock.java

示例12: MeterMetric

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public MeterMetric(ScheduledExecutorService tickThread, TimeUnit rateUnit) {
    this.rateUnit = rateUnit;
    this.future = tickThread.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            tick();
        }
    }, INTERVAL, INTERVAL, TimeUnit.SECONDS);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:MeterMetric.java

示例13: newFixedRateSchedule

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * Returns a {@link Scheduler} that schedules the task using the {@link
 * ScheduledExecutorService#scheduleAtFixedRate} method.
 *
 * @param initialDelay the time to delay first execution
 * @param period the period between successive executions of the task
 * @param unit the time unit of the initialDelay and period parameters
 */
public static Scheduler newFixedRateSchedule(
    final long initialDelay, final long period, final TimeUnit unit) {
  checkNotNull(unit);
  checkArgument(period > 0, "period must be > 0, found %s", period);
  return new Scheduler() {
    @Override
    public Future<?> schedule(
        AbstractService service, ScheduledExecutorService executor, Runnable task) {
      return executor.scheduleAtFixedRate(task, initialDelay, period, unit);
    }
  };
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:AbstractScheduledService.java

示例14: startMonitoring

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public ScheduledFuture<?> startMonitoring(ScheduledExecutorService ses)
{
    ScheduledFuture<?> monitorTask =
        ses.scheduleAtFixedRate(
            this, 0,
            LOADMONITOR_SAMPLING_INTERVAL, TimeUnit.MILLISECONDS);
    return monitorTask;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:9,代码来源:LoadMonitor.java

示例15: syncServerSchedule

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
private void syncServerSchedule() {
    ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("server"));
    scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        public void run() {
            try {
                if (RegistryUtil.isOpenProviderBerkeleyDB) {
                    checkTotalCount();
                    syncToDB();
                }
            } catch (Exception e) {
                logger.error("sync server data error:", e);
            }
        }
    }, 30, interval, TimeUnit.SECONDS);
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:16,代码来源:ServerSyncSchedule.java


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