Java Code Examples for java.util.concurrent.ScheduledThreadPoolExecutor#scheduleWithFixedDelay()
The following examples show how to use
java.util.concurrent.ScheduledThreadPoolExecutor#scheduleWithFixedDelay() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsistencyWatchdogServer.java From saros with GNU General Public License v2.0 | 6 votes |
@Override public void start() { if (!session.isHost()) throw new IllegalStateException("Component can only be run on the session's host"); session.addActivityProducer(this); stopManager.addBlockable(this); editorManager.addSharedEditorListener(sharedEditorListener); checksumCalculationExecutor = new ScheduledThreadPoolExecutor( 1, new NamedThreadFactory("Consistency-Watchdog-Server", false)); checksumCalculationExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); checksumCalculationFuture = checksumCalculationExecutor.scheduleWithFixedDelay( checksumCalculation, 0, CHECKSUM_CALCULATION_INTERVAL, TimeUnit.MILLISECONDS); }
Example 2
Source File: ProbeController.java From kieker with Apache License 2.0 | 6 votes |
@Override protected void init() { if (this.enabled && (this.monitoringController != null)) { final SamplingController samplingController = this.monitoringController.getSamplingController(); final ScheduledThreadPoolExecutor scheduler = samplingController.periodicSensorsPoolExecutor; if ((this.configFileReadIntervall > 0) && (null != scheduler)) { scheduler.scheduleWithFixedDelay(this.configFileReader, this.configFileReadIntervall, this.configFileReadIntervall, TimeUnit.SECONDS); } else { if ((this.configFileReadIntervall > 0) && (null == scheduler)) { ProbeController.LOGGER.warn( "Failed to enable regular reading of adaptive monitoring config file. '{}' must be > 0!", ConfigurationKeys.PERIODIC_SENSORS_EXECUTOR_POOL_SIZE); } } } }
Example 3
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * A fixed delay task with overflowing period should not prevent a * one-shot task from executing. * https://bugs.openjdk.java.net/browse/JDK-8051859 */ public void testScheduleWithFixedDelay_overflow() throws Exception { final CountDownLatch delayedDone = new CountDownLatch(1); final CountDownLatch immediateDone = new CountDownLatch(1); final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final Runnable immediate = new Runnable() { public void run() { immediateDone.countDown(); }}; final Runnable delayed = new Runnable() { public void run() { delayedDone.countDown(); p.submit(immediate); }}; p.scheduleWithFixedDelay(delayed, 0L, Long.MAX_VALUE, SECONDS); await(delayedDone); await(immediateDone); } }
Example 4
Source File: SolrRrdBackendFactory.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a factory. * @param solrClient SolrClient to use * @param collection collection name where documents are stored (typically this is * {@link CollectionAdminParams#SYSTEM_COLL}) * @param syncPeriod synchronization period in seconds - how often modified * databases are stored as updated Solr documents * @param timeSource time source */ public SolrRrdBackendFactory(SolrClient solrClient, String collection, int syncPeriod, TimeSource timeSource) { this.solrClient = solrClient; this.timeSource = timeSource; this.collection = collection; this.syncPeriod = syncPeriod; if (log.isDebugEnabled()) { log.debug("Created {}", hashCode()); } this.idPrefixLength = ID_PREFIX.length() + ID_SEP.length(); syncService = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(2, new SolrNamedThreadFactory("SolrRrdBackendFactory")); syncService.setRemoveOnCancelPolicy(true); syncService.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); syncService.scheduleWithFixedDelay(() -> maybeSyncBackends(), timeSource.convertDelay(TimeUnit.SECONDS, syncPeriod, TimeUnit.MILLISECONDS), timeSource.convertDelay(TimeUnit.SECONDS, syncPeriod, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); }
Example 5
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * scheduleWithFixedDelay executes runnable after given initial delay */ public void testSchedule5() throws Exception { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { final long startTime = System.nanoTime(); final CountDownLatch done = new CountDownLatch(1); Runnable task = new CheckedRunnable() { public void realRun() { done.countDown(); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); }}; ScheduledFuture f = p.scheduleWithFixedDelay(task, timeoutMillis(), LONG_DELAY_MS, MILLISECONDS); await(done); assertTrue(millisElapsedSince(startTime) >= timeoutMillis()); f.cancel(true); } }
Example 6
Source File: DelayOverflow.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void scheduleAtTheEndOfTime(ScheduledThreadPoolExecutor pool, Runnable r, int how) { switch (how) { case 0: pool.schedule(r, Long.MAX_VALUE, MILLISECONDS); break; case 1: pool.schedule(Executors.callable(r), Long.MAX_VALUE, DAYS); break; case 2: pool.scheduleWithFixedDelay(r, Long.MAX_VALUE, 1000, NANOSECONDS); break; case 3: pool.scheduleAtFixedRate(r, Long.MAX_VALUE, 1000, MILLISECONDS); break; default: fail(String.valueOf(how)); } }
Example 7
Source File: DelayOverflow.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
void scheduleNow(ScheduledThreadPoolExecutor pool, Runnable r, int how) { switch (how) { case 0: pool.schedule(r, 0, MILLISECONDS); break; case 1: pool.schedule(Executors.callable(r), 0, DAYS); break; case 2: pool.scheduleWithFixedDelay(r, 0, 1000, NANOSECONDS); break; case 3: pool.scheduleAtFixedRate(r, 0, 1000, MILLISECONDS); break; default: fail(String.valueOf(how)); } }
Example 8
Source File: HeartbeatDispatcher.java From saros with GNU General Public License v2.0 | 6 votes |
@Override public void start() { session.addActivityProducer(this); heartbeatScheduledExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("JupiterHeartbeat")); /* Schedule the heart-beat once per minute, this should be absolutely sufficient. * NOTE: This might even be to frequent for a lot of open documents, but * that likely causes other performance problems anyway. * Suggestion: store a map of the documents. Invoke the heart-beat more frequently but only fire heart-beats for a subset of documents so * that we do not produce too much traffic at once. * E.G: We have 50 documents, on the first interval fire changes for the first 10 documents. * On the next interval fire changes for the next 10 documents on so on. */ // client documents should only be accessed by the main thread heartbeatScheduledExecutor.scheduleWithFixedDelay( () -> uiSynchronizer.syncExec(this::dispatchHeartbeats), 1, 1, TimeUnit.MINUTES); }
Example 9
Source File: NodeHealthCheckService.java From eventeum with Apache License 2.0 | 6 votes |
public NodeHealthCheckService(BlockchainService blockchainService, ReconnectionStrategy reconnectionStrategy, SubscriptionService subscriptionService, EventeumValueMonitor valueMonitor, EventStoreService eventStoreService, Integer syncingThreshold, ScheduledThreadPoolExecutor taskScheduler, Long healthCheckPollInterval) { this.eventStoreService = eventStoreService; this.blockchainService = blockchainService; this.reconnectionStrategy = reconnectionStrategy; this.subscriptionService = subscriptionService; this.syncingThreshold = syncingThreshold; nodeStatus = NodeStatus.SUBSCRIBED; currentBlock = valueMonitor.monitor( "currentBlock", blockchainService.getNodeName(), new AtomicLong(0)); nodeStatusGauge = valueMonitor.monitor( "status", blockchainService.getNodeName(), new AtomicInteger(NodeStatus.SUBSCRIBED.ordinal())); syncing = valueMonitor.monitor("syncing", blockchainService.getNodeName(), new AtomicInteger(0)); taskScheduler.scheduleWithFixedDelay(() -> this.checkHealth() ,0, healthCheckPollInterval, TimeUnit.MILLISECONDS); }
Example 10
Source File: ScheduledExecutorTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * scheduleWithFixedDelay throws RejectedExecutionException if shutdown */ public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.shutdown(); p.scheduleWithFixedDelay(new NoOpRunnable(), MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (RejectedExecutionException success) { } catch (SecurityException ok) {} } }
Example 11
Source File: RepairServiceLauncher.java From io with Apache License 2.0 | 5 votes |
/** * コンストラクタ. Webコンテナ起動時に呼ばれる。 */ public RepairServiceLauncher() { // 同時起動はしないため、Threadは1つ. executor = new ScheduledThreadPoolExecutor(1); executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false); // リペアツールの実行をスケジュールする. RepairAdsService service = new RepairAdsService(); executor.scheduleWithFixedDelay(service, DcCoreConfig.getAdsRepairInitialDelayInSec(), DcCoreConfig.getAdsRepairIntervalInSec(), TimeUnit.SECONDS); logger.info(String.format("RepairAds scheduled with delay interval %d sec.", DcCoreConfig.getAdsRepairIntervalInSec())); }
Example 12
Source File: AbstractReservationSystem.java From hadoop with Apache License 2.0 | 5 votes |
@Override public void serviceStart() throws Exception { if (planFollower != null) { scheduledExecutorService = new ScheduledThreadPoolExecutor(1); scheduledExecutorService.scheduleWithFixedDelay(planFollower, 0L, planStepSize, TimeUnit.MILLISECONDS); } super.serviceStart(); }
Example 13
Source File: ScheduledExecutorTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * scheduleWithFixedDelay throws RejectedExecutionException if shutdown */ public void testScheduleWithFixedDelay1_RejectedExecutionException() throws InterruptedException { final ScheduledThreadPoolExecutor p = new ScheduledThreadPoolExecutor(1); try (PoolCleaner cleaner = cleaner(p)) { try { p.shutdown(); p.scheduleWithFixedDelay(new NoOpRunnable(), MEDIUM_DELAY_MS, MEDIUM_DELAY_MS, MILLISECONDS); shouldThrow(); } catch (RejectedExecutionException success) { } catch (SecurityException ok) {} } }
Example 14
Source File: KCVSLog.java From grakn with GNU Affero General Public License v3.0 | 5 votes |
@Override public synchronized void registerReaders(ReadMarker readMarker, Iterable<MessageReader> readers) { ResourceUnavailableException.verifyOpen(isOpen, "Log", name); Preconditions.checkArgument(!Iterables.isEmpty(readers), "Must specify at least one reader"); Preconditions.checkArgument(readMarker != null, "Read marker cannot be null"); Preconditions.checkArgument(this.readMarker == null || this.readMarker.isCompatible(readMarker), "Provided read marker is not compatible with existing read marker for previously registered readers"); if (this.readMarker == null) this.readMarker = readMarker; boolean firstRegistration = this.readers.isEmpty(); for (MessageReader reader : readers) { Preconditions.checkNotNull(reader); if (!this.readers.contains(reader)) this.readers.add(reader); } if (firstRegistration && !this.readers.isEmpty()) { //Custom rejection handler so that messages are processed in-thread when executor has been closed readExecutor = new ScheduledThreadPoolExecutor(numReadThreads, (r, executor) -> r.run()); msgPullers = new MessagePuller[manager.readPartitionIds.length * numBuckets]; int pos = 0; for (int partitionId : manager.readPartitionIds) { for (int bucketId = 0; bucketId < numBuckets; bucketId++) { msgPullers[pos] = new MessagePuller(partitionId, bucketId); LOG.debug("Creating LOG read executor: initialDelay={} delay={} unit={}", INITIAL_READER_DELAY.toNanos(), readPollingInterval.toNanos(), TimeUnit.NANOSECONDS); readExecutor.scheduleWithFixedDelay( msgPullers[pos], INITIAL_READER_DELAY.toNanos(), readPollingInterval.toNanos(), TimeUnit.NANOSECONDS); pos++; } } readExecutor.scheduleWithFixedDelay( new MessageReaderStateUpdater(), INITIAL_READER_DELAY.toNanos(), readPollingInterval.toNanos(), TimeUnit.NANOSECONDS); } }
Example 15
Source File: SchedulerManager.java From nuls-v2 with MIT License | 5 votes |
public boolean createTransactionScheduler(Chain chain) { //网络新交易 ThreadUtils.createAndRunThread(TxConstant.TX_THREAD, new NetTxProcessTask(chain)); //孤儿交易 ScheduledThreadPoolExecutor orphanTxExecutor = ThreadUtils.createScheduledThreadPool(1, new NulsThreadFactory(TxConstant.TX_ORPHAN_THREAD)); orphanTxExecutor.scheduleAtFixedRate(new OrphanTxProcessTask(chain), TxConstant.TX_ORPHAN_TASK_INITIALDELAY, TxConstant.TX_ORPHAN_TASK_PERIOD, TimeUnit.SECONDS); //未确认交易清理机制Task ScheduledThreadPoolExecutor unconfirmedTxExecutor = ThreadUtils.createScheduledThreadPool(1, new NulsThreadFactory(TxConstant.TX_CLEAN_THREAD)); //固定延迟时间 unconfirmedTxExecutor.scheduleWithFixedDelay(new ClearUnconfirmedTxProcessTask(chain), TxConstant.TX_CLEAN_TASK_INITIALDELAY, TxConstant.TX_CLEAN_TASK_PERIOD, TimeUnit.SECONDS); return true; }
Example 16
Source File: TaskTools.java From pampas with Apache License 2.0 | 5 votes |
public static void scheduledTask(String taskName, long intervalMilliseconds, Supplier supplier) { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); executor.scheduleWithFixedDelay(() -> { try { supplier.get(); } catch (Throwable throwable) { log.debug("{}调度失败:{}", taskName, throwable.getMessage(), throwable); } }, 0, intervalMilliseconds, TimeUnit.MILLISECONDS); }
Example 17
Source File: M3U8LiveLoader.java From Aria with Apache License 2.0 | 5 votes |
/** * 开始循环加载m3u8信息 */ private void startLoaderLiveInfo() { mTimer = new ScheduledThreadPoolExecutor(1); mTimer.scheduleWithFixedDelay(new Runnable() { @Override public void run() { mInfoTask.run(); } }, 0, mM3U8Option.getLiveUpdateInterval(), TimeUnit.MILLISECONDS); }
Example 18
Source File: JobTrigger.java From actframework with Apache License 2.0 | 4 votes |
@Override protected void delayedSchedule(JobManager manager, Job job) { ScheduledThreadPoolExecutor executor = manager.executor(); ScheduledFuture future = executor.scheduleWithFixedDelay(job, seconds, seconds, TimeUnit.SECONDS); manager.futureScheduled(job.id(), future); }
Example 19
Source File: KeySegmentLockManager.java From KitDB with Apache License 2.0 | 4 votes |
public void start(ScheduledThreadPoolExecutor stp) { stp.scheduleWithFixedDelay(this::check, 30, 30, TimeUnit.SECONDS); }
Example 20
Source File: KeySegmentLockManager.java From KitDB with Apache License 2.0 | 4 votes |
public KeySegmentLockManager(ScheduledThreadPoolExecutor stp) { stp.scheduleWithFixedDelay(this::check, 30, 30, TimeUnit.SECONDS); }