Tabnine Logo
ScheduledExecutorService.scheduleAtFixedRate
Code IndexAdd Tabnine to your IDE (free)

How to use
scheduleAtFixedRate
method
in
java.util.concurrent.ScheduledExecutorService

Best Java code snippets using java.util.concurrent.ScheduledExecutorService.scheduleAtFixedRate (Showing top 20 results out of 13,347)

Refine searchRefine arrow

  • Executors.newScheduledThreadPool
  • Executors.newSingleThreadScheduledExecutor
  • Logger.info
origin: code4craft/webmagic

private void initFlushThread() {
  flushThreadPool = Executors.newScheduledThreadPool(1);
  flushThreadPool.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      flush();
    }
  }, 10, 10, TimeUnit.SECONDS);
}
origin: shuzheng/zheng

private void scheduleClockUpdating() {
  ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
    @Override
    public Thread newThread(Runnable runnable) {
      Thread thread = new Thread(runnable, "System Clock");
      thread.setDaemon(true);
      return thread;
    }
  });
  scheduler.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      now.set(System.currentTimeMillis());
    }
  }, period, period, TimeUnit.MILLISECONDS);
}
origin: alibaba/jstorm

public void register(TimeUnit timeUnit) {
  future = threadPool.scheduleAtFixedRate(this, firstTime, frequency, timeUnit);
  LOG.info("Successfully register timer " + this);
}
origin: alipay/sofa-rpc

public ConsulManager(String host, int port) {
  client = new ConsulClient(host, port);
  ttlScheduler = new TtlScheduler(client);
  scheduleRegistry = Executors.newScheduledThreadPool(1, new NamedThreadFactory("retryFailedTtl", true));
  scheduleRegistry.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      try {
        retryFailedTtl();
      } catch (Throwable e) {
        if (LOGGER.isInfoEnabled()) {
          LOGGER.info("retry registry znode failed", e);
        }
      }
    }
  }, ConsulConstants.HEARTBEAT_CIRCLE, ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS);
  if (LOGGER.isInfoEnabled()) {
    LOGGER.info("ConsulEcwidClient init finish. client host:" + host + ", port:" + port);
  }
}
origin: qunarcorp/qmq

private CachedOfflineStateManager() {
  refresh();
  scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder().setNameFormat("meta-info-offlinestate-refresh-%d").build());
  scheduledExecutor.scheduleAtFixedRate(this::refresh, REFRESH_PERIOD_SECONDS, REFRESH_PERIOD_SECONDS, TimeUnit.SECONDS);
  log.info("CachedOfflineStateManager started");
}
origin: linkedin/kafka-monitor

@Override
public synchronized void start() {
 _executor.scheduleAtFixedRate(new Runnable() {
  @Override
  public void run() {
   try {
    reportMetrics();
   } catch (Exception e) {
    LOG.error(_name + "/KafkaMetricsReporterService failed to report metrics", e);
   }
  }
 }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS);
 LOG.info("{}/KafkaMetricsReporterService started", _name);
}
origin: alipay/sofa-rpc

public ConsulManager(String host, int port) {
  client = new ConsulClient(host, port);
  ttlScheduler = new TtlScheduler(client);
  scheduleRegistry = Executors.newScheduledThreadPool(1, new NamedThreadFactory("retryFailedTtl", true));
  scheduleRegistry.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      try {
        retryFailedTtl();
      } catch (Throwable e) {
        if (LOGGER.isInfoEnabled()) {
          LOGGER.info("retry registry znode failed", e);
        }
      }
    }
  }, ConsulConstants.HEARTBEAT_CIRCLE, ConsulConstants.HEARTBEAT_CIRCLE, TimeUnit.MILLISECONDS);
  if (LOGGER.isInfoEnabled()) {
    LOGGER.info("ConsulEcwidClient init finish. client host:" + host + ", port:" + port);
  }
}
origin: Netflix/conductor

@Inject
public EventProcessor(ExecutionService executionService, MetadataService metadataService,
           ActionProcessor actionProcessor, EventQueues eventQueues, JsonUtils jsonUtils, Configuration config) {
  this.executionService = executionService;
  this.metadataService = metadataService;
  this.actionProcessor = actionProcessor;
  this.eventQueues = eventQueues;
  this.jsonUtils = jsonUtils;
  int executorThreadCount = config.getIntProperty("workflow.event.processor.thread.count", 2);
  if (executorThreadCount > 0) {
    executorService = Executors.newFixedThreadPool(executorThreadCount);
    refresh();
    Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::refresh, 60, 60, TimeUnit.SECONDS);
    logger.info("Event Processing is ENABLED. executorThreadCount set to {}", executorThreadCount);
  } else {
    logger.warn("Event processing is DISABLED. executorThreadCount set to {}", executorThreadCount);
  }
}
origin: stackoverflow.com

 @WebListener
public class BackgroundJobManager implements ServletContextListener {

  private ScheduledExecutorService scheduler;

  @Override
  public void contextInitialized(ServletContextEvent event) {
    scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new SomeDailyJob(), 0, 1, TimeUnit.DAYS);
    scheduler.scheduleAtFixedRate(new SomeHourlyJob(), 0, 1, TimeUnit.HOURS);
    scheduler.scheduleAtFixedRate(new SomeQuarterlyJob(), 0, 15, TimeUnit.MINUTES);
  }

  @Override
  public void contextDestroyed(ServletContextEvent event) {
    scheduler.shutdownNow();
  }

}
origin: pinterest/secor

private static void loop(ProgressMonitor progressMonitor, long interval) {
final ProgressMonitor monitor = progressMonitor;
Runnable runner = new Runnable() {
  public void run() {
    try {
    monitor.exportStats();
    } catch (Throwable t) {
    LOG.error("Progress monitor failed", t);
    }
  }
  };
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(runner, 0, interval, TimeUnit.SECONDS);
}
origin: springside/springside4

/**
 * 启动定时任务.
 */
public void start(long period, TimeUnit unit) {
  if (started) {
    throw new IllegalStateException("Scheduler had been started before");
  }
  executor.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      try {
        report();
      } catch (Throwable e) {
        logger.error(e.getMessage(), e);
      }
    }
  }, period, period, unit);
  started = true;
  logger.info("metric reporters started.");
}
origin: apache/drill

@Override
public void start(HiveConf hiveConf) throws Exception {
 this.hiveConf = hiveConf;
 HiveTxnManager mgr = TxnManagerFactory.getTxnManagerFactory().getTxnManager(hiveConf);
 if(!mgr.supportsAcid()) {
  LOG.info(this.getClass().getName() + " not started since " +
   mgr.getClass().getName()  + " does not support Acid.");
  return;//there are no transactions in this case
 }
 pool = Executors.newScheduledThreadPool(1, new ThreadFactory() {
  private final AtomicInteger threadCounter = new AtomicInteger();
  @Override
  public Thread newThread(Runnable r) {
   return new Thread(r, HouseKeeperServiceBase.this.getClass().getName() + "-" + threadCounter.getAndIncrement());
  }
 });
 TimeUnit tu = TimeUnit.MILLISECONDS;
 pool.scheduleAtFixedRate(getScheduedAction(hiveConf, isAliveCounter), getStartDelayMs(),
  getIntervalMs(), tu);
 LOG.info("Started " + this.getClass().getName() + " with delay/interval = " + getStartDelayMs() + "/" +
  getIntervalMs() + " " + tu);
}
origin: apache/shiro

protected void startReloadThread() {
  if (this.reloadIntervalSeconds > 0) {
    this.scheduler = Executors.newSingleThreadScheduledExecutor();
    ((ScheduledExecutorService) this.scheduler).scheduleAtFixedRate(this, reloadIntervalSeconds, reloadIntervalSeconds, TimeUnit.SECONDS);
  }
}
origin: ReactiveX/RxJava

static void tryStart(boolean purgeEnabled) {
  if (purgeEnabled) {
    for (;;) {
      ScheduledExecutorService curr = PURGE_THREAD.get();
      if (curr != null) {
        return;
      }
      ScheduledExecutorService next = Executors.newScheduledThreadPool(1, new RxThreadFactory("RxSchedulerPurge"));
      if (PURGE_THREAD.compareAndSet(curr, next)) {
        next.scheduleAtFixedRate(new ScheduledTask(), PURGE_PERIOD_SECONDS, PURGE_PERIOD_SECONDS, TimeUnit.SECONDS);
        return;
      } else {
        next.shutdownNow();
      }
    }
  }
}
origin: linkedin/kafka-monitor

@Override
public synchronized void start() {
 _executor.scheduleAtFixedRate(
  new Runnable() {
   @Override
   public void run() {
    try {
     reportMetrics();
    } catch (Exception e) {
     LOG.error(_name + "/StatsdMetricsReporterService failed to report metrics", e);
    }
   }
  }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS
 );
 LOG.info("{}/StatsdMetricsReporterService started", _name);
}
origin: apache/kylin

@SuppressWarnings("rawtypes")
@Ignore("why test JDK feature?")
@Test
public void testSchedulerPool() throws InterruptedException {
  logger.info("testSchedulerPool");
  ScheduledExecutorService fetchPool = Executors.newScheduledThreadPool(1);
  final CountDownLatch countDownLatch = new CountDownLatch(3);
  ScheduledFuture future = fetchPool.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      countDownLatch.countDown();
    }
  }, 0, 1, TimeUnit.SECONDS);
  assertTrue("countDownLatch should reach zero in 15 secs", countDownLatch.await(7, TimeUnit.SECONDS));
  assertTrue("future should still running", future.cancel(true));
  final CountDownLatch countDownLatch2 = new CountDownLatch(3);
  ScheduledFuture future2 = fetchPool.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      countDownLatch2.countDown();
      throw new RuntimeException();
    }
  }, 0, 1, TimeUnit.SECONDS);
  assertFalse("countDownLatch2 should NOT reach zero in 15 secs", countDownLatch2.await(7, TimeUnit.SECONDS));
  assertFalse("future2 should has been stopped", future2.cancel(true));
}
origin: stackoverflow.com

 private ScheduledExecutorService scheduler;

public void contextInitialized(ServletContextEvent event) {
  scheduler = Executors.newSingleThreadScheduledExecutor();
  scheduler.scheduleAtFixedRate(new CleanDBTask(), 0, 1, TimeUnit.HOURS);
  scheduler.scheduleAtFixedRate(new StatisticsTask(), 0, 15, TimeUnit.MINUTES);
}

public void contextDestroyed(ServletContextEvent event) {
  scheduler.shutdownNow();
}
origin: apache/storm

public LocalClient(LocalServer server) {
  _server = server;
  _pendingDueToUnregisteredServer = new LinkedBlockingQueue<>();
  _pendingFlusher = Executors.newScheduledThreadPool(1, new ThreadFactory() {
    @Override
    public Thread newThread(Runnable runnable) {
      Thread thread = new Thread(runnable);
      thread.setName("LocalClientFlusher-" + thread.getId());
      thread.setDaemon(true);
      return thread;
    }
  });
  _pendingFlusher.scheduleAtFixedRate(new Runnable() {
    @Override
    public void run() {
      try {
        //Ensure messages are flushed even if no more sends are performed
        flushPending();
      } catch (Throwable t) {
        LOG.error("Uncaught throwable in pending message flusher thread, messages may be lost", t);
        throw new RuntimeException(t);
      }
    }
  }, 5, 5, TimeUnit.SECONDS);
}
origin: linkedin/kafka-monitor

@Override
public synchronized void start() {
 _executor.scheduleAtFixedRate(
  new Runnable() {
   @Override
   public void run() {
    try {
     reportMetrics();
    } catch (Exception e) {
     LOG.error(_name + "/DefaultMetricsReporterService failed to report metrics", e);
    }
   }
  }, _reportIntervalSec, _reportIntervalSec, TimeUnit.SECONDS
 );
 LOG.info("{}/DefaultMetricsReporterService started", _name);
}
origin: stackoverflow.com

 @WebListener
public class BackgroundJobManager implements ServletContextListener {

  private ScheduledExecutorService scheduler;

  @Override
  public void contextInitialized(ServletContextEvent event) {
    scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new YourParsingJob(), 0, 5, TimeUnit.HOUR);
  }

  @Override
  public void contextDestroyed(ServletContextEvent event) {
    scheduler.shutdownNow();
  }

}
java.util.concurrentScheduledExecutorServicescheduleAtFixedRate

Javadoc

Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

Popular methods of ScheduledExecutorService

  • schedule
    Creates and executes a ScheduledFuture that becomes enabled after the given delay.
  • shutdown
  • scheduleWithFixedDelay
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • shutdownNow
  • awaitTermination
  • submit
  • execute
  • isShutdown
  • isTerminated
  • invokeAll
  • invokeAny
  • <init>
  • invokeAny,
  • <init>

Popular in Java

  • Making http requests using okhttp
  • startActivity (Activity)
  • getSharedPreferences (Context)
  • findViewById (Activity)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now