當前位置: 首頁>>代碼示例>>Java>>正文


Java ScheduledFuture類代碼示例

本文整理匯總了Java中java.util.concurrent.ScheduledFuture的典型用法代碼示例。如果您正苦於以下問題:Java ScheduledFuture類的具體用法?Java ScheduledFuture怎麽用?Java ScheduledFuture使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScheduledFuture類屬於java.util.concurrent包,在下文中一共展示了ScheduledFuture類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createBuckets

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@Bean
public ScheduledFuture<List<String>> createBuckets(MinioClient minioClient, ScheduledExecutorService executorService, S3ClientProperties clientProps) {
	return executorService.schedule(() -> {
		try {
			for (String bucket : clientProps.buckets) {
				logger.info("Checking bucket: {}", bucket);
				if (minioClient.bucketExists(bucket))
					continue;
				logger.info("Bucket doesn't exist, creating one");
				minioClient.makeBucket(bucket);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		} finally {
			logger.info("Bucket successfully created");
		}
		return clientProps.buckets;
	}, 5, TimeUnit.SECONDS);
}
 
開發者ID:codenergic,項目名稱:theskeleton,代碼行數:20,代碼來源:S3ClientConfig.java

示例2: applyEnergyBuff

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public final void applyEnergyBuff(final MapleCharacter applyto, final boolean infinity, int targets) {
    final long starttime = System.currentTimeMillis();
    if (infinity) {
        applyto.getClient().getSession().write(BuffPacket.giveEnergyChargeTest(0, info.get(MapleStatInfo.time) / 1000, targets));
        applyto.registerEffect(this, starttime, null, applyto.getId());
    } else {
        final EnumMap<CharacterTemporaryStat, Integer> stat = new EnumMap<>(CharacterTemporaryStat.class);
        stat.put(CharacterTemporaryStat.EnergyCharged, 10000);
        applyto.cancelEffect(this, true, -1, stat);
        applyto.getMap().broadcastMessage(applyto, BuffPacket.giveEnergyChargeTest(applyto.getId(), 10000, info.get(MapleStatInfo.time) / 1000), false);
        final CancelEffectAction cancelAction = new CancelEffectAction(applyto, this, starttime, stat);
        final ScheduledFuture<?> schedule = BuffTimer.getInstance().schedule(cancelAction, ((starttime + info.get(MapleStatInfo.time)) - System.currentTimeMillis()));
        applyto.registerEffect(this, starttime, schedule, stat, false, info.get(MapleStatInfo.time), applyto.getId());

    }
}
 
開發者ID:ergothvs,項目名稱:Lucid2.0,代碼行數:17,代碼來源:MapleStatEffect.java

示例3: testScheduleWithDelay

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@Test
public void testScheduleWithDelay() throws ExecutionException, InterruptedException {
  MockRunLoop runLoop = new MockRunLoop();
  try {
    assertEquals(0, runLoop.getThreadPool().getCorePoolSize());
    ScheduledFuture future = runLoop.schedule(new Runnable() {
      @Override
      public void run() {
      }
    }, 500L);
    assertEquals(1, runLoop.getThreadPool().getCorePoolSize());

    future.get();
    assertTrue(runLoop.errors.isEmpty());
  } finally {
    runLoop.getExecutorService().shutdownNow();
  }
}
 
開發者ID:firebase,項目名稱:firebase-admin-java,代碼行數:19,代碼來源:DefaultRunLoopTest.java

示例4: scheduleWithFixedDelay

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
    ScheduledFuture scheduledFuture = null;
    try {
        TaskDefine taskDefine = resolveTaskName(task);
        if (taskDefine.getType().equals(TaskDefine.TYPE_SPRING_TASK)) {
            super.scheduleWithFixedDelay(task, startTime, delay);
            LOGGER.debug(":添加本地任務[" + taskDefine.stringKey() + "]");
        } else {
            taskDefine.setStartTime(startTime);
            taskDefine.setPeriod(delay);
            scheduleTask.addTask(taskDefine);
            scheduledFuture = super.scheduleWithFixedDelay(taskWrapper(task), startTime, delay);
            LOGGER.debug(currenScheduleServer.getUuid() + ":自動向集群注冊任務[" + taskDefine.stringKey() + "]");
        }
    } catch (Exception e) {
        LOGGER.error("update task error", e);
    }
    return scheduledFuture;
}
 
開發者ID:liuht777,項目名稱:uncode-scheduler,代碼行數:21,代碼來源:SchedulerTaskManager.java

示例5: main

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public static void main(String[] args) {
    final LoadMonitor monitor = new LoadMonitor(null);
    final ScheduledExecutorService scheduler =
        Executors.newScheduledThreadPool(1);
    final ScheduledFuture<?> monitorTask =
        monitor.startMonitoring(scheduler);
    final ScheduledFuture<?> printTask =
        monitor.printMonitoring(scheduler);

    // Run the tasks for 2 minutes
    scheduler.schedule(
        new Runnable() {
            public void run() {
                monitorTask.cancel(true);
                printTask.cancel(true);
            }
        }, 5*60, TimeUnit.SECONDS);
}
 
開發者ID:nsg-ethz,項目名稱:iTAP-controller,代碼行數:19,代碼來源:LoadMonitor.java

示例6: scheduleAtFixedRate

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@Override
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
    ScheduledFuture scheduledFuture = null;
    try {
        TaskDefine taskDefine = resolveTaskName(task);
        if (taskDefine.getType().equals(TaskDefine.TYPE_SPRING_TASK)) {
            super.scheduleAtFixedRate(task, period);
            LOGGER.debug(":添加本地任務[" + taskDefine.stringKey() + "]");
        } else {
            taskDefine.setPeriod(period);
            scheduleTask.addTask(taskDefine);
            scheduledFuture = super.scheduleAtFixedRate(taskWrapper(task), period);
            LOGGER.debug(currenScheduleServer.getUuid() + ":自動向集群注冊任務[" + taskDefine.stringKey() + "]");
        }

    } catch (Exception e) {
        LOGGER.error("update task error", e);
    }
    return scheduledFuture;
}
 
開發者ID:liuht777,項目名稱:uncode-scheduler,代碼行數:21,代碼來源:SchedulerTaskManager.java

示例7: questTimeLimit

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public void questTimeLimit(final MapleQuest quest, int time) {
    ScheduledFuture<?> sf = TimerManager.getInstance().schedule(new Runnable() {
        @Override
        public void run() {
            announce(MaplePacketCreator.questExpire(quest.getId()));
            MapleQuestStatus newStatus = new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
            newStatus.setForfeited(getQuest(quest).getForfeited() + 1);
            updateQuest(newStatus);
        }
    }, time);
    announce(MaplePacketCreator.addQuestTimeLimit(quest.getId(), time));
    timers.add(sf);
}
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:14,代碼來源:MapleCharacter.java

示例8: a

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public static void a() {
    try {
        for (WeakReference weakReference : a) {
            ScheduledFuture scheduledFuture = (ScheduledFuture) weakReference.get();
            if (scheduledFuture != null) {
                scheduledFuture.cancel(false);
            }
        }
        a.clear();
        if (!b.isShutdown()) {
            b.shutdown();
        }
        if (!d.isShutdown()) {
            d.shutdown();
        }
        b.awaitTermination(c, TimeUnit.SECONDS);
        d.awaitTermination(c, TimeUnit.SECONDS);
    } catch (Exception e) {
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:f.java

示例9: registerEffect

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public void registerEffect(MapleStatEffect effect, long starttime, ScheduledFuture<?> schedule) {
if (effect.isDragonBlood()) {
    prepareDragonBlood(effect);
} else if (effect.isBerserk()) {
    checkBerserk();
} else if (effect.isBeholder()) {
    final int beholder = DarkKnight.BEHOLDER;
    if (beholderHealingSchedule != null) {
        beholderHealingSchedule.cancel(false);
    }
    if (beholderBuffSchedule != null) {
        beholderBuffSchedule.cancel(false);
    }
    Skill bHealing = SkillFactory.getSkill(DarkKnight.AURA_OF_BEHOLDER);
    int bHealingLvl = getSkillLevel(bHealing);
    if (bHealingLvl > 0) {
        final MapleStatEffect healEffect = bHealing.getEffect(bHealingLvl);
        int healInterval = healEffect.getX() * 1000;
        beholderHealingSchedule = TimerManager.getInstance().register(new Runnable() {
            @Override
            public void run() {
                addHP(healEffect.getHp());
                client.announce(MaplePacketCreator.showOwnBuffEffect(beholder, 2));
                getMap().broadcastMessage(MapleCharacter.this, MaplePacketCreator.summonSkill(getId(), beholder, 5), true);
                getMap().broadcastMessage(MapleCharacter.this, MaplePacketCreator.showOwnBuffEffect(beholder, 2), false);
            }
        }, healInterval, healInterval);
    }
    Skill bBuff = SkillFactory.getSkill(DarkKnight.HEX_OF_BEHOLDER);
    if (getSkillLevel(bBuff) > 0) {
        final MapleStatEffect buffEffect = bBuff.getEffect(getSkillLevel(bBuff));
        int buffInterval = buffEffect.getX() * 1000;
        beholderBuffSchedule = TimerManager.getInstance().register(new Runnable() {
 
開發者ID:NovaStory,項目名稱:AeroStory,代碼行數:34,代碼來源:MapleCharacter.java

示例10: testCancel

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@Test
public void testCancel() throws InterruptedException, ExecutionException {
    RScheduledExecutorService executor = redisson.getExecutorService("test");
    ScheduledFuture<?> future1 = executor.schedule(new ScheduledRunnableTask("executed1"), 1, TimeUnit.SECONDS);
    cancel(future1);
    Thread.sleep(2000);
    assertThat(redisson.getAtomicLong("executed1").isExists()).isFalse();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:RedissonScheduledExecutorServiceTest.java

示例11: getFestivalManagerSchedule

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
/**
    * Primarily used to terminate the Festival Manager, when the Seven Signs period changes.
    *
    * @return ScheduledFuture festManagerScheduler
    */
   @SuppressWarnings("rawtypes")
protected final ScheduledFuture getFestivalManagerSchedule()
   {
       if (_managerScheduledTask == null)
           startFestivalManager();

       return _managerScheduledTask;
   }
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:14,代碼來源:SevenSignsFestival.java

示例12: startHelloSender

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
/**
 * Starts the hello timer which sends hello packet every configured seconds.
 *
 * @param channel netty channel instance
 */
public void startHelloSender(Channel channel) {
    log.debug("IsisInterfaceImpl::startHelloSender");
    if (!helloSenderStarted) {
        isisHelloPduSender = new IsisHelloPduSender(channel, this);
        exServiceHello = Executors.newSingleThreadScheduledExecutor();
        final ScheduledFuture<?> helloHandle =
                exServiceHello.scheduleAtFixedRate(isisHelloPduSender, 0,
                                                   helloInterval, TimeUnit.SECONDS);
        helloSenderStarted = true;
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:17,代碼來源:DefaultIsisInterface.java

示例13: printMonitoring

import java.util.concurrent.ScheduledFuture; //導入依賴的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:nsg-ethz,項目名稱:iTAP-controller,代碼行數:14,代碼來源:LoadMonitor.java

示例14: schedule

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
public ScheduledFuture<?> schedule() {
	this.scheduledExecutionTime = this.trigger.nextExecutionTime(this.triggerContext);
	if (this.scheduledExecutionTime == null) {
		return null;
	}
	setTimer(getTimerManager().schedule(this, this.scheduledExecutionTime));
	return this;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:TimerManagerTaskScheduler.java

示例15: scheduleAiAtFixedRate

import java.util.concurrent.ScheduledFuture; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public ScheduledFuture scheduleAiAtFixedRate(Runnable r, long initial, long delay)
{
	try
	{
		if (delay < 0) delay = 0;
		if (initial < 0) initial = 0;
		return _aiScheduledThreadPool.scheduleAtFixedRate(r, initial, delay, TimeUnit.MILLISECONDS);
	} catch (RejectedExecutionException e) { return null; /* shutdown, ignore */ }
}
 
開發者ID:L2jBrasil,項目名稱:L2jBrasil,代碼行數:11,代碼來源:ThreadPoolManager.java


注:本文中的java.util.concurrent.ScheduledFuture類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。