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


Java ScheduledExecutorService.scheduleWithFixedDelay方法代码示例

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


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

示例1: HTTPconThread

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public HTTPconThread(int id,URLdetails obj,int time){
	this.obj=obj;
	this.id = id;
	this.time=time;
	this.index = Controller.getList().indexOf(obj);
	final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.scheduleWithFixedDelay(new Runnable() {
		@Override
		public void run() {
			if(Controller.getList().indexOf(obj)==-1){
				executorService.shutdown();
			}
			testIt(obj.getUrl());
		}
	}, 0, time, TimeUnit.SECONDS);
}
 
开发者ID:naeemkhan12,项目名称:websiteMonitor,代码行数:17,代码来源:HTTPconThread.java

示例2: sendMsg

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public void sendMsg() {
        System.out.println("sendMsg");
        ScheduledExecutorService newScheduledThreadPool = Executors.newSingleThreadScheduledExecutor();
        Random random = new Random();
//        int delay = random.nextInt(2) + 1;
        int delay = 3;
        System.out.println("delay = " + delay);

        newScheduledThreadPool.scheduleWithFixedDelay(new Monitor(), 1, delay, TimeUnit.SECONDS);
    }
 
开发者ID:wanghan0501,项目名称:WiFiProbeAnalysis,代码行数:11,代码来源:Monitor.java

示例3: postConstruct

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

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * startCredentialRefresher should be used only for long running
 * methods like Thrift source. For all privileged methods that use a UGI, the
 * credentials are checked automatically and refreshed before the
 * privileged method is executed in the UGIExecutor
 */
@Override
public void startCredentialRefresher() {
  int CHECK_TGT_INTERVAL = 120; // seconds
  ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
  scheduler.scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      try {
        ugi.checkTGTAndReloginFromKeytab();
      } catch (IOException e) {
        LOG.warn("Error occured during checkTGTAndReloginFromKeytab() for user " +
                ugi.getUserName(), e);
      }
    }
  }, CHECK_TGT_INTERVAL, CHECK_TGT_INTERVAL, TimeUnit.SECONDS);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:23,代码来源:KerberosAuthenticator.java

示例5: createLogSyncer

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public static ScheduledExecutorService createLogSyncer() {
  final ScheduledExecutorService scheduler =
    Executors.newSingleThreadScheduledExecutor(
      new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
          final Thread t = Executors.defaultThreadFactory().newThread(r);
          t.setDaemon(true);
          t.setName("Thread for syncLogs");
          return t;
        }
      });
  ShutdownHookManager.get().addShutdownHook(new Runnable() {
      @Override
      public void run() {
        TaskLog.syncLogsShutdown(scheduler);
      }
    }, 50);
  scheduler.scheduleWithFixedDelay(
      new Runnable() {
        @Override
        public void run() {
          TaskLog.syncLogs();
        }
      }, 0L, 5L, TimeUnit.SECONDS);
  return scheduler;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TaskLog.java

示例6: RequestSignatureRuleImpl

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public RequestSignatureRuleImpl ( final ScheduledExecutorService executor, final SignatureRequestBuilder builder, final RequestValidator validator, final X509KeySelector keySelector, final AuditLogService auditLogService, final boolean indent, final ScriptExecutor postProcessor, final AuthenticationImplementation authenticator, final int reloadPeriod )
{
    this.builder = builder;
    this.validator = validator;
    this.auditLogService = auditLogService;
    this.indent = indent;
    this.postProcessor = postProcessor;
    this.authenticator = authenticator;
    this.keySelector = keySelector;

    if ( reloadPeriod > 0 )
    {
        logger.debug ( "Starting reload job: {} ms", reloadPeriod );

        this.job = executor.scheduleWithFixedDelay ( new Runnable () {

            @Override
            public void run ()
            {
                reload ();
            }
        }, 0, reloadPeriod, TimeUnit.MILLISECONDS );
    }
    else
    {
        logger.debug ( "Reloading once" );
        reload ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:30,代码来源:RequestSignatureRuleImpl.java

示例7: main

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
    new ExecutorServiceMetrics(es, "executor.sample", emptyList()).bindTo(registry);

    es.scheduleWithFixedDelay(() -> Mono.delay(Duration.ofMillis(20)).block(), 0,
            10, TimeUnit.MILLISECONDS);

    while(true) {}
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:11,代码来源:ExecutorServiceSample.java

示例8: newFixedDelaySchedule

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

示例9: FDTServer

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
public FDTServer(int port) throws Exception {
    hasToRun = new AtomicBoolean(true);

    // We are not very happy to welcome new clients ... so the priority will be lower
    executor = Utils.getStandardExecService("[ Acceptable ServersThreadPool ] ",
            5,
            10,
            new ArrayBlockingQueue<Runnable>(65500),
            Thread.NORM_PRIORITY - 2);
    ssc = ServerSocketChannel.open();
    ssc.configureBlocking(false);

    ss = ssc.socket();

    String listenIP = config.getListenAddress();
    if (listenIP == null) {
        ss.bind(new InetSocketAddress(port));
    }
    else
    {
        ss.bind(new InetSocketAddress(InetAddress.getByName(listenIP), port));
    }

    sel = Selector.open();
    ssc.register(sel, SelectionKey.OP_ACCEPT);

    if (config.isGSIModeEnabled()) {
        FDTGSIServer gsiServer = new FDTGSIServer(config.getGSIPort());
        gsiServer.start();
        logger.log(Level.INFO, "FDT started in GSI mode on port: " + config.getGSIPort());
    }
    // Monitoring & Nice Prnting
    final ScheduledExecutorService monitoringService = Utils.getMonitoringExecService();

    monitoringService.scheduleWithFixedDelay(new FDTServerMonitorTask(), 10, 10, TimeUnit.SECONDS);

    // in SSH mode this is a ACK message for the client to inform it that the server started ok
    // (the server stdout is piped to client through the SSH channel)
    System.out.println("READY");
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:41,代码来源:FDTServer.java

示例10: fixedRate

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
private static void fixedRate() throws Exception {
  // starts immediately after the task has run
  ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

  Runnable task = () -> {
    System.out.println("Scheduling: " + System.nanoTime() + " " + ZonedDateTime.now());
    try {
      TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    System.out.println("Ready:      " +  System.nanoTime() + " " + ZonedDateTime.now());
  };

  int initialDelay = 0;
  int period = 8;
  executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);

  ScheduledExecutorService watch = Executors.newScheduledThreadPool(1);
  Runnable watcher = () -> {
    if (new File("stop").exists()) {
      System.out.println("Stopping executor because file 'stop' exists.");
      executor.shutdown();
      watch.shutdown();
    }
  };

  watch.scheduleWithFixedDelay(watcher, 1, 1, TimeUnit.SECONDS);
}
 
开发者ID:EHRI,项目名称:rs-aggregator,代码行数:30,代码来源:TestTest.java

示例11: init

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * creates the scheduledExecutor thread pool and starts schedule timers which
 * check for expired entry timers and adjust the message display timer
 */
public void init()
{
    /* thread to fill announcement queues and thread to empty announcement queues,
     share the same scheduler to avoid collisions */
    ScheduledExecutorService announcementScheduler = Executors.newSingleThreadScheduledExecutor();
    // fill
    announcementScheduler.scheduleWithFixedDelay(
            new EntryProcessor(type.FILL),
            30, 30, TimeUnit.SECONDS);
    // empty
    announcementScheduler.scheduleWithFixedDelay(
            new EntryProcessor(type.EMPTY),
            15, 20, TimeUnit.SECONDS);

    // scheduler for threads to adjust entry display timers
    ScheduledExecutorService updateDisplayScheduler = Executors.newSingleThreadScheduledExecutor();
    // 1 day timer
    updateDisplayScheduler.scheduleWithFixedDelay(
            new EntryProcessor(type.UPDATE3),
            12*60*60, 12*60*60, TimeUnit.SECONDS);
    // 1 hour timer
    updateDisplayScheduler.scheduleWithFixedDelay(
            new EntryProcessor(type.UPDATE2),
            60*30, 60*30, TimeUnit.SECONDS);
    // 4.5 min timer
    updateDisplayScheduler.scheduleWithFixedDelay(
            new EntryProcessor(type.UPDATE1),
            60*4+30, 60*3, TimeUnit.SECONDS);
}
 
开发者ID:notem,项目名称:Saber-Bot,代码行数:34,代码来源:EntryManager.java

示例12: setupPseudoDNSServer

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

        hasStaticIp = false;
        ipRefreshURL = "http://hartzkai.freehostia.com/thesis/changeip.php";

        final ScheduledExecutorService ses = Executors.newSingleThreadScheduledExecutor();
        ses.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                String urlParameters = "";
                NetworkUtilities.executePost(ipRefreshURL, urlParameters);
                // System.out.println("Refreshed Ip at:" + ipRefreshURL);
            }
        }, 0, 1, TimeUnit.MINUTES);
    }
 
开发者ID:Hatzen,项目名称:EasyPeasyVPN,代码行数:16,代码来源:Main.java

示例13: scheduleWithFixedDelay

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
	ScheduledExecutorService executor = getScheduledExecutor();
	long initialDelay = startTime.getTime() - System.currentTimeMillis();
	try {
		return executor.scheduleWithFixedDelay(errorHandlingTask(task, true), initialDelay, delay, TimeUnit.MILLISECONDS);
	}
	catch (RejectedExecutionException ex) {
		throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:ThreadPoolTaskScheduler.java

示例14: startMongoServerThread

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
private static void startMongoServerThread(){
    ms= new MongoSender(collection);
    ScheduledExecutorService scheduledExecutorService2 =
            Executors.newScheduledThreadPool(1);
    ScheduledFuture scheduledFuture2 =
            scheduledExecutorService2.scheduleWithFixedDelay(ms, 1, 5, TimeUnit.MINUTES);
}
 
开发者ID:LithiumSR,项目名称:media_information_service,代码行数:8,代码来源:MongoDBInterface.java

示例15: main

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * Runs the application as a giveaway updater
 * @throws Exception 
 */
public static void main() throws Exception
{
    LoggerFactory.getLogger("Updater").info("Updater starting.");
    
    // load tokens from a file
    // 0 - bot token
    // 1 - database host
    // 2 - database username
    // 3 - database pass
    List<String> tokens = Files.readAllLines(Paths.get("updater.txt"));
    
    // connects to the database
    Database database = new Database(tokens.get(1), tokens.get(2), tokens.get(3));
    
    // migrate the old giveaways if the file exists
    //migrateGiveaways(database);
    
    // make a 'JDA' rest client
    RestJDA restJDA = new RestJDA(tokens.get(0));
    
    // make a pool to run the update loop
    ScheduledExecutorService pool = Executors.newSingleThreadScheduledExecutor();
    
    // create an index to track time
    AtomicLong index = new AtomicLong(0);
    
    pool.scheduleWithFixedDelay(() -> {
        // set vars for this iteration
        long current = index.getAndIncrement();
        Instant now = Instant.now();
        
        // end giveaways with end status
        database.giveaways.getGiveaways(Status.ENDNOW).forEach(giveaway -> {
            database.giveaways.deleteGiveaway(giveaway.messageId);
            giveaway.end(restJDA);
        });
        
        // end giveaways that have run out of time
        database.giveaways.getGiveawaysEndingBefore(now.plusMillis(1900)).forEach(giveaway -> {
            database.giveaways.deleteGiveaway(giveaway.messageId);
            giveaway.end(restJDA);
        });
        
        if(current%300==0)
        {
            // update all giveaways
            database.giveaways.getGiveaways().forEach(giveaway -> giveaway.update(restJDA, database, now));
        }
        else if(current%60==0)
        {
            // update giveaways within 1 hour of ending
            database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(60*60)).forEach(giveaway -> giveaway.update(restJDA, database, now));
        }
        else if(current%5==0)
        {
            // update giveaways within 3 minutes of ending
            database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(3*60)).forEach(giveaway -> giveaway.update(restJDA, database, now));
        }
        else
        {
            // update giveaways within 10 seconds of ending
            database.giveaways.getGiveawaysEndingBefore(now.plusSeconds(6)).forEach(giveaway -> giveaway.update(restJDA, database, now));
        }
    }, 0, 1, TimeUnit.SECONDS);
}
 
开发者ID:jagrosh,项目名称:GiveawayBot,代码行数:70,代码来源:Updater.java


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