本文整理汇总了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);
}
示例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());
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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) {
}
}
示例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() {
示例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();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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 */ }
}