本文整理匯總了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**/
}