Java Code Examples for java.util.concurrent.ScheduledFuture#getDelay()
The following examples show how to use
java.util.concurrent.ScheduledFuture#getDelay() .
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: ThreadUtils.java From rqueue with Apache License 2.0 | 6 votes |
public static void waitForTermination( Logger log, Future<?> future, long waitTimeInMillis, String msg, Object... msgParams) { if (future == null) { return; } boolean completedOrCancelled = future.isCancelled() || future.isDone(); if (!completedOrCancelled) { if (future instanceof ScheduledFuture) { ScheduledFuture f = (ScheduledFuture) future; if (f.getDelay(TimeUnit.MILLISECONDS) > Constants.MIN_DELAY) { return; } } } waitForShutdown(log, future, waitTimeInMillis, msg, msgParams); }
Example 2
Source File: JmxCacheBuster.java From hbase with Apache License 2.0 | 6 votes |
/** * For JMX to forget about all previously exported metrics. */ public static void clearJmxCache() { if (LOG.isTraceEnabled()) { LOG.trace("clearing JMX Cache" + StringUtils.stringifyException(new Exception())); } //If there are more then 100 ms before the executor will run then everything should be merged. ScheduledFuture future = fut.get(); if ((future != null && (!future.isDone() && future.getDelay(TimeUnit.MILLISECONDS) > 100))) { // BAIL OUT return; } if (stopped.get()) { return; } future = executor.getExecutor().schedule(new JmxCacheBusterRunnable(), 5, TimeUnit.SECONDS); fut.set(future); }
Example 3
Source File: ScheduledExecutorServiceTest.java From threadly with Mozilla Public License 2.0 | 6 votes |
@Test public void scheduleCallableCancelTest() { ScheduledExecutorService scheduler = makeScheduler(1); try { TestCallable tcDelay = new TestCallable(0); ScheduledFuture<Object> delayF = scheduler.schedule(tcDelay, 20, TimeUnit.MILLISECONDS); long delay = delayF.getDelay(TimeUnit.MILLISECONDS); boolean canceled = delayF.cancel(true); assertTrue(delay <= 20); if (canceled) { assertTrue(delayF.isCancelled()); } } finally { scheduler.shutdownNow(); } }
Example 4
Source File: ReschedulingRunnable.java From spring-analysis-note with MIT License | 5 votes |
@Override public long getDelay(TimeUnit unit) { ScheduledFuture<?> curr; synchronized (this.triggerContextMonitor) { curr = obtainCurrentFuture(); } return curr.getDelay(unit); }
Example 5
Source File: InMemoryJobService.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public ZonedDateTime getScheduledTime(String id) { if (scheduledJobs.containsKey(id)) { ScheduledFuture<?> scheduled = scheduledJobs.get(id); long remainingTime = scheduled.getDelay(TimeUnit.MILLISECONDS); if (remainingTime > 0) { return ZonedDateTime.from(Instant.ofEpochMilli(System.currentTimeMillis() + remainingTime)); } } return null; }
Example 6
Source File: ReschedulingRunnable.java From java-technology-stack with MIT License | 5 votes |
@Override public long getDelay(TimeUnit unit) { ScheduledFuture<?> curr; synchronized (this.triggerContextMonitor) { curr = obtainCurrentFuture(); } return curr.getDelay(unit); }
Example 7
Source File: ReschedulingRunnable.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public long getDelay(TimeUnit unit) { ScheduledFuture<?> curr; synchronized (this.triggerContextMonitor) { curr = this.currentFuture; } return curr.getDelay(unit); }
Example 8
Source File: ReschedulingRunnable.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public long getDelay(TimeUnit unit) { ScheduledFuture<?> curr; synchronized (this.triggerContextMonitor) { curr = this.currentFuture; } return curr.getDelay(unit); }
Example 9
Source File: ReschedulingRunnable.java From audit4j-core with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @see java.util.concurrent.Delayed#getDelay(java.util.concurrent.TimeUnit) * */ @Override public long getDelay(TimeUnit unit) { ScheduledFuture<?> curr; synchronized (this.triggerContextMonitor) { curr = this.currentFuture; } return curr.getDelay(unit); }
Example 10
Source File: Executors3.java From java8-tutorial with MIT License | 5 votes |
private static void test1() throws InterruptedException { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); Runnable task = () -> System.out.println("Scheduling: " + System.nanoTime()); int delay = 3; ScheduledFuture<?> future = executor.schedule(task, delay, TimeUnit.SECONDS); TimeUnit.MILLISECONDS.sleep(1337); long remainingDelay = future.getDelay(TimeUnit.MILLISECONDS); System.out.printf("Remaining Delay: %sms\n", remainingDelay); }
Example 11
Source File: DropService.java From aion-germany with GNU General Public License v3.0 | 4 votes |
/** * When player clicks on dead NPC to request drop list * * @param player * @param npcId */ public void requestDropList(Player player, int npcId) { DropNpc dropNpc = DropRegistrationService.getInstance().getDropRegistrationMap().get(npcId); if (player == null || dropNpc == null) { return; } if (!dropNpc.containsKey(player.getObjectId()) && !dropNpc.isFreeForAll()) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_LOOT_NO_RIGHT); return; } if (dropNpc.isBeingLooted()) { PacketSendUtility.sendPacket(player, SM_SYSTEM_MESSAGE.STR_LOOT_FAIL_ONLOOTING); return; } Set<DropItem> dropItems = DropRegistrationService.getInstance().getCurrentDropMap().get(npcId); if (dropItems == null || dropItems.size() == 0) { dropItems = Collections.emptySet(); ThreadPoolManager.getInstance().schedule(new Runnable() { @Override public void run() { return; } }, 350); //Blocks Loot for 350ms and return if DropList is empty } else { dropNpc.setBeingLooted(player); VisibleObject visObj = World.getInstance().findVisibleObject(npcId); if (visObj instanceof Npc) { Npc npc = ((Npc) visObj); ScheduledFuture<?> decayTask = (ScheduledFuture<?>) npc.getController().cancelTask(TaskId.DECAY); if (decayTask != null) { long reamingDecayTime = decayTask.getDelay(TimeUnit.MILLISECONDS); dropNpc.setReamingDecayTime(reamingDecayTime); } } PacketSendUtility.sendPacket(player, new SM_LOOT_ITEMLIST(npcId, dropItems, player)); PacketSendUtility.sendPacket(player, new SM_LOOT_STATUS(npcId, 2)); player.unsetState(CreatureState.ACTIVE); player.setState(CreatureState.LOOTING); player.setLootingNpcOid(npcId); PacketSendUtility.broadcastPacket(player, new SM_EMOTION(player, EmotionType.START_LOOT, 0, npcId), true); } }
Example 12
Source File: ProgMainLambdaThreadScheduledExectors06.java From javase with MIT License | 4 votes |
private static void test1() throws InterruptedException { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); Runnable task = () -> System.out.println("Scheduling: " + System.nanoTime() + ", Now = " + Instant.now()); int delay = 3; ScheduledFuture<?> future = executor.schedule(task, delay, TimeUnit.SECONDS); TimeUnit.MILLISECONDS.sleep(1337); long remainingDelay = future.getDelay(TimeUnit.MILLISECONDS); System.out.printf("Remaining Delay: %sms\n", remainingDelay); TimeUnit.MILLISECONDS.sleep(10000); shutDown(executor); }