本文整理汇总了Java中java.util.concurrent.ScheduledFuture.get方法的典型用法代码示例。如果您正苦于以下问题:Java ScheduledFuture.get方法的具体用法?Java ScheduledFuture.get怎么用?Java ScheduledFuture.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ScheduledFuture
的用法示例。
在下文中一共展示了ScheduledFuture.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: testMultipleTasksWithTimeShift
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Test
public void testMultipleTasksWithTimeShift() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test");
ScheduledFuture<?> future1 = executor.schedule(new ScheduledRunnableTask("executed1"), 2, TimeUnit.SECONDS);
ScheduledFuture<?> future2 = executor.schedule(new ScheduledRunnableTask("executed2"), 3, TimeUnit.SECONDS);
ScheduledFuture<?> future3 = executor.schedule(new ScheduledRunnableTask("executed3"), 4, TimeUnit.SECONDS);
long startTime = System.currentTimeMillis();
future1.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(2000L, 2200L);
future2.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(3000L, 3200L);
future3.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(4000L, 4200L);
assertThat(redisson.getAtomicLong("executed1").get()).isEqualTo(1);
assertThat(redisson.getAtomicLong("executed2").get()).isEqualTo(1);
assertThat(redisson.getAtomicLong("executed3").get()).isEqualTo(1);
}
示例3: run
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Override
public void run()
{
try
{
logger.info("Start feed collect");
ScheduledFuture<Feed> future = Executors.newSingleThreadScheduledExecutor()
.schedule(new YouTubeParser(),
0,
TimeUnit.MICROSECONDS);
Feed feed = future.get();
logger.info("Feed was collect. Feed size: {}", feed.getVideos().size());
logger.info("Start collect images");
imageCollector.collectImages(feed);
LastFeedContainer.setFeed(feed);
}
catch (Exception e)
{
logger.error("Error", e);
}
}
示例4: cancel
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
private void cancel(ScheduledFuture<?> future1) throws InterruptedException, ExecutionException {
assertThat(future1.cancel(true)).isTrue();
boolean canceled = false;
try {
future1.get();
} catch (CancellationException e) {
canceled = true;
}
assertThat(canceled).isTrue();
}
示例5: testMultipleTasks
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Test
public void testMultipleTasks() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test");
ScheduledFuture<?> future1 = executor.schedule(new ScheduledRunnableTask("executed1"), 5, TimeUnit.SECONDS);
ScheduledFuture<?> future2 = executor.schedule(new ScheduledRunnableTask("executed2"), 5, TimeUnit.SECONDS);
ScheduledFuture<?> future3 = executor.schedule(new ScheduledRunnableTask("executed3"), 5, TimeUnit.SECONDS);
long startTime = System.currentTimeMillis();
future1.get();
future2.get();
future3.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(5000L, 5200L);
assertThat(redisson.getAtomicLong("executed1").get()).isEqualTo(1);
assertThat(redisson.getAtomicLong("executed2").get()).isEqualTo(1);
assertThat(redisson.getAtomicLong("executed3").get()).isEqualTo(1);
}
示例6: testRunnableTask
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Test
public void testRunnableTask() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test");
ScheduledFuture<?> future = executor.schedule(new ScheduledRunnableTask("executed"), 5, TimeUnit.SECONDS);
long startTime = System.currentTimeMillis();
future.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(5000L, 5200L);
assertThat(redisson.getAtomicLong("executed").get()).isEqualTo(1);
}
示例7: testCallableTask
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Test
public void testCallableTask() throws InterruptedException, ExecutionException {
RScheduledExecutorService executor = redisson.getExecutorService("test");
ScheduledFuture<Long> future = executor.schedule(new ScheduledCallableTask(), 3, TimeUnit.SECONDS);
long startTime = System.currentTimeMillis();
future.get();
assertThat(System.currentTimeMillis() - startTime).isBetween(3000L, 3200L);
assertThat(future.get()).isEqualTo(100);
}
示例8: get
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
@Override
public Object get() throws InterruptedException, ExecutionException {
ScheduledFuture<?> curr;
synchronized (this.triggerContextMonitor) {
curr = this.currentFuture;
}
return curr.get();
}
示例9: logNotifification
import java.util.concurrent.ScheduledFuture; //导入方法依赖的package包/类
/**
* Logs the deletion of the bearer
* @param schedFuture
*/
private static void logNotifification(ScheduledFuture<DeleteBearerCall> schedFuture)
{
DeleteBearerCall bearerInstance = null;
try {
bearerInstance = schedFuture.get();
LOG.info("Context delete success for DPNTopic: {}, teid: {}", bearerInstance.dpnTopic, bearerInstance.s1u_sgw_gtpu_teid);
} catch (InterruptedException | ExecutionException e) {
ErrorLog.logError(e.getStackTrace());
}
/*** North bound cache notification code here**/
}