Example usage for java.util.concurrent ScheduledExecutorService scheduleAtFixedRate

List of usage examples for java.util.concurrent ScheduledExecutorService scheduleAtFixedRate

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledExecutorService scheduleAtFixedRate.

Prototype

public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);

Source Link

Document

Submits 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.

Usage

From source file:com.mmj.app.lucene.search.build.SearchBuilder.java

@PostConstruct
public void cronCache() {
    ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1);
    newScheduledThreadPool.scheduleAtFixedRate(new Runnable() {

        @Override/*w  ww  . j  a  va2 s.  c  o  m*/
        public void run() {
            try {
                build(SearchTypeEnum.USER, DEFAULT_VERSION, SearchTypeEnum.USER.getDateFetcher(null));
                build(SearchTypeEnum.TOPIC, DEFAULT_VERSION, SearchTypeEnum.TOPIC.getDateFetcher(null));
            } catch (Throwable e) {
                logger.error("start searchBuilder error,build search index error!", e);
            }
        }

    }, 1, 24 * 60, TimeUnit.MINUTES);
}

From source file:org.wso2.carbon.integrator.core.handler.EndpointHolder.java

private EndpointHolder() {
    //retry interval 2 hour
    long interval = 2;
    ScheduledExecutorService globalExecutorService = Executors.newSingleThreadScheduledExecutor();
    globalExecutorService.scheduleAtFixedRate(this, interval, interval, TimeUnit.HOURS);
}

From source file:pl.datamatica.traccar.api.fcm.Daemon.java

protected void start(ScheduledExecutorService scheduler, long delay, long period) {
    scheduler.scheduleAtFixedRate(runnable, delay, period, TimeUnit.MINUTES);
}

From source file:com.hurence.logisland.connect.opc.da.OpcDaSourceConnectorTest.java

@Test
@Ignore//ww  w . j a v a  2s. c o m
public void e2eTest() throws Exception {
    OpcDaSourceConnector connector = new OpcDaSourceConnector();
    Map<String, String> properties = new HashMap<>();
    properties.put(OpcDaSourceConnector.PROPERTY_AUTH_NTLM_DOMAIN, "OPC-9167C0D9342");
    properties.put(CommonDefinitions.PROPERTY_CONNECTION_SOCKET_TIMEOUT, "2000");
    properties.put(OpcDaSourceConnector.PROPERTY_AUTH_NTLM_PASSWORD, "opc");
    properties.put(OpcDaSourceConnector.PROPERTY_AUTH_NTLM_USER, "OPC");
    properties.put(CommonDefinitions.PROPERTY_SERVER_URI, "opc.da://192.168.99.100");
    properties.put(OpcDaSourceConnector.PROPERTY_SERVER_CLSID, "F8582CF2-88FB-11D0-B850-00C0F0104305");
    properties.put(CommonDefinitions.PROPERTY_TAGS_ID, "Random.Real8,Triangle Waves.Int4");
    properties.put(CommonDefinitions.PROPERTY_TAGS_STREAM_MODE, "SUBSCRIBE,POLL");
    properties.put(CommonDefinitions.PROPERTY_TAGS_SAMPLING_RATE, "PT3S,PT1S");
    properties.put(OpcDaSourceConnector.PROPERTY_SESSION_REFRESH_PERIOD, "1000");
    properties.put(OpcDaSourceConnector.PROPERTY_TAGS_DATA_TYPE_OVERRIDE, "0,8");

    connector.start(properties);
    OpcDaSourceTask task = new OpcDaSourceTask();
    task.start(connector.taskConfigs(1).get(0));
    ScheduledExecutorService es = Executors.newSingleThreadScheduledExecutor();
    Gson json = new Gson();
    es.scheduleAtFixedRate(() -> {
        try {
            task.poll().stream()
                    .map(a -> org.apache.commons.lang3.tuple.Pair.of(
                            new Date((Long) a.sourceOffset().get(OpcRecordFields.SAMPLED_TIMESTAMP)),
                            json.toJson(a)))
                    .forEach(System.out::println);
        } catch (InterruptedException e) {
            //do nothing
        }
    }, 0, 10, TimeUnit.MILLISECONDS);

    Thread.sleep(600000);
    task.stop();
    es.shutdown();
    connector.stop();
}

From source file:org.verwandlung.voj.judger.application.ApplicationBootstrap.java

/**
 * ?Web?./* w w w .j  a  va2  s.c o  m*/
 * ?Web???Keep-Alive?.
 */
private void setupHeartBeat() {
    final int INITIAL_DELAY = 0;
    final int PERIOD = 25;

    ApplicationHeartbeat heartbeat = applicationContext.getBean(ApplicationHeartbeat.class);
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    scheduler.scheduleAtFixedRate(heartbeat, INITIAL_DELAY, PERIOD, TimeUnit.MINUTES);
}

From source file:org.xdi.oxd.server.license.LicenseUpdateService.java

private void scheduleUpdatePinger() {
    final ScheduledExecutorService executorService = Executors
            .newSingleThreadScheduledExecutor(CoreUtils.daemonThreadFactory());
    executorService.scheduleAtFixedRate(new Runnable() {
        @Override// w  ww  .  j  av  a  2s  . c  o m
        public void run() {
            updateLicenseFromServer();
        }
    }, 1, conf.getLicenseCheckPeriodInHours(), TimeUnit.HOURS);
}

From source file:org.sbs.goodcrawler.fetcher.FailedPageBackup.java

public void init() {
    ignoreFailedPage = Boolean.getBoolean(config.getString(GlobalConstants.ignoreFailedPages, "true"));
    if (!ignoreFailedPage) {
        Queue = new LinkedBlockingDeque<Page>(config.getInt(GlobalConstants.failedPagesQueueSize, 2000));
        // /*from   ww w . j av a 2s . c  o m*/
        BackupFailedPages backup = new BackupFailedPages();
        Thread failedPagesBackupThread = new Thread(backup, "failed-pages-backup-thread");
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(failedPagesBackupThread, 60, 60, TimeUnit.SECONDS);
    }
}

From source file:com.magnet.mmx.util.AlertEventsManagerTest.java

public void testInterEmailTime() {
    setupMocks();/*from w w w . ja  va 2 s . c o  m*/
    long testDurationMinutes = 5;
    MMXConfiguration.getConfiguration().setValue(MMXConfigKeys.ALERT_EMAIL_ENABLED, "true");
    MMXConfiguration.getConfiguration().setValue(MMXConfigKeys.ALERT_INTER_EMAIL_TIME_MINUTES, "1");
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
    ScheduledFuture<?> future = executorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            AlertEventsManager.post(getRandomEvent());
        }
    }, 0L, 500, TimeUnit.MILLISECONDS);
    List<ScheduledFuture<?>> list = new ArrayList<ScheduledFuture<?>>();
    list.add(future);
    executorService.schedule(new StopTestTask(list), testDurationMinutes, TimeUnit.MINUTES);
    while (!future.isDone())
        ;
    LOGGER.trace("testInterEmailTime : average inter email time = {}", getAvg(elapsedTimes));
}

From source file:com.flipkart.phantom.runtime.impl.hystrix.HystrixMetricsAggregator.java

@Override
public void afterPropertiesSet() throws Exception {
    if (frequency > 1) {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        metricsSnapshotReporter = new MetricsSnapshotReporterWithAggregation(frequency);
        scheduler.scheduleAtFixedRate((Runnable) metricsSnapshotReporter, 10, 10, TimeUnit.SECONDS);
    } else {/*from  www  .  j av a 2  s .c  o m*/
        metricsSnapshotReporter = new MetricsSnapshotReporterDefault();
    }
}

From source file:rmblworx.tools.timey.SimpleAlarm.java

/**
 * Startet die Alarmerkennung.//  w ww.  jav  a2 s  .  com
 *
 * @param delayPerThread
 *            Mazahl fr den Ausfuehrungsintervall
 * @param timeUnit
 *            Einheit fr den Ausfuehrungsintervall
 */
public void startAlarmdetection(final int delayPerThread, final TimeUnit timeUnit) {
    if (delayPerThread < 1) {
        throw new ValueMinimumArgumentException();
    } else if (timeUnit == null) {
        throw new NullArgumentException();
    }
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(THREAD_POOL_SIZE);
    final AlarmRunnable alarmDetection = (AlarmRunnable) this.springContext.getBean("alarmRunnable");

    scheduler.scheduleAtFixedRate(alarmDetection, 0, delayPerThread, timeUnit);
}