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