本文整理了Java中java.util.concurrent.FutureTask.get()
方法的一些代码示例,展示了FutureTask.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FutureTask.get()
方法的具体详情如下:
包路径:java.util.concurrent.FutureTask
类名称:FutureTask
方法名:get
暂无
代码示例来源:origin: stackoverflow.com
Read: 1
Read: 2
Exception in thread "main" java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:228)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at test.InputStreamWithTimeoutTest.main(InputStreamWithTimeoutTest.java:74)
代码示例来源:origin: QNJR-GROUP/EasyTransaction
@Override
public T get() throws InterruptedException, ExecutionException {
futureTask.run();
return futureTask.get();
}
代码示例来源:origin: QNJR-GROUP/EasyTransaction
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException,
ExecutionException, TimeoutException {
futureTask.run();
return futureTask.get(timeout, unit);
}
代码示例来源:origin: junit-team/junit4
/**
* Wait for the test task, returning the exception thrown by the test if the
* test failed, an exception indicating a timeout if the test timed out, or
* {@code null} if the test passed.
*/
private Throwable getResult(FutureTask<Throwable> task, Thread thread) {
try {
if (timeout > 0) {
return task.get(timeout, timeUnit);
} else {
return task.get();
}
} catch (InterruptedException e) {
return e; // caller will re-throw; no need to call Thread.interrupt()
} catch (ExecutionException e) {
// test failed; have caller re-throw the exception thrown by the test
return e.getCause();
} catch (TimeoutException e) {
return createTimeoutException(thread);
}
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected Result get(long timeout, TimeUnit unit)
throws InterruptedException, ExecutionException, TimeoutException {
return future.get(timeout, unit);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected Result get() throws InterruptedException, ExecutionException {
return future.get();
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public JobExecutionResult get()
throws InterruptedException {
try {
return super.get();
} catch (ExecutionException ee) {
return JobExecutionResult.createFailureResult(ee.getCause());
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public JobExecutionResult get(long timeout, TimeUnit unit)
throws InterruptedException, TimeoutException {
try {
return super.get(timeout, unit);
} catch (ExecutionException ee) {
return JobExecutionResult.createFailureResult(ee.getCause());
}
}
}
代码示例来源:origin: google/guava
private static void runNInterruptsTest(
int times, SettableFuture<String> future, FutureTask<Boolean> interruptReporter)
throws InterruptedException, ExecutionException, TimeoutException {
Thread waitingThread = new Thread(interruptReporter);
waitingThread.start();
for (int i = 0; i < times; i++) {
waitingThread.interrupt();
}
future.set(RESULT);
assertEquals(times > 0, (boolean) interruptReporter.get(20, SECONDS));
}
代码示例来源:origin: robolectric/robolectric
@Override
public V get() throws InterruptedException, ExecutionException {
while (!isDone()) {
scheduler.advanceToNextPostedRunnable();
}
return super.get();
}
}
代码示例来源:origin: apache/hive
private static Set<String> getAllWorkDagIds(List<FutureTask<Set<String>>> tasks)
throws ExecutionException, InterruptedException {
Set<String> allWorkDagIds = Sets.newHashSet();
for (FutureTask<Set<String>> task : tasks) {
allWorkDagIds.addAll(task.get());
}
return allWorkDagIds;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultExecutor() throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(ExecutorConfig.class);
ExecutorService executor = context.getBean("executor", ExecutorService.class);
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
public String call() throws Exception {
return "foo";
}
});
executor.execute(task);
assertEquals("foo", task.get());
}
代码示例来源:origin: twosigma/beakerx
private TryResult getResult(FutureTask<TryResult> ret) {
TryResult o;
try {
o = ret.get();
} catch (Exception e) {
e.printStackTrace();
return TryResult.createError(e.getMessage());
}
if (ret.isCancelled())
return TryResult.createError("Cancelled");
return o;
}
代码示例来源:origin: google/guava
/**
* Confirms that the test code triggers {@link InterruptedException} in a standard {@link Future}.
*/
public void testMakeUninterruptible_plainFutureSanityCheck() throws Exception {
SettableFuture<String> future = SettableFuture.create();
FutureTask<Boolean> wasInterrupted = untimedInterruptReporter(future, true);
Thread waitingThread = new Thread(wasInterrupted);
waitingThread.start();
waitingThread.interrupt();
try {
wasInterrupted.get();
fail();
} catch (ExecutionException expected) {
assertTrue(
expected.getCause().toString(), expected.getCause() instanceof InterruptedException);
}
}
代码示例来源:origin: airbnb/lottie-android
@Override public void run() {
while (true) {
if (isInterrupted() || taskComplete) {
return;
}
if (task.isDone()) {
try {
setResult(task.get());
} catch (InterruptedException | ExecutionException e) {
setResult(new LottieResult<T>(e));
}
taskComplete = true;
stopTaskObserverIfNeeded();
}
}
}
};
代码示例来源:origin: apache/incubator-druid
/**
* Wait for the test task, returning the exception thrown by the test if the
* test failed, an exception indicating a timeout if the test timed out, or
* {@code null} if the test passed.
*/
private Throwable getResult(FutureTask<Throwable> task, Thread thread)
{
try {
if (timeout > 0) {
return task.get(timeout, timeUnit);
} else {
return task.get();
}
}
catch (InterruptedException e) {
return e; // caller will re-throw; no need to call Thread.interrupt()
}
catch (ExecutionException e) {
// test failed; have caller re-throw the exception thrown by the test
return e.getCause();
}
catch (TimeoutException e) {
return createTimeoutException(thread);
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* This is a basic test of the heartbeat scheduler logic. It steps through the execution of a
* single dummy executor.
*/
@Test
public void serialHeartbeatThread() throws Exception {
FutureTask<Void> task = new FutureTask<>(new DummyHeartbeatTestCallable());
Thread thread = new Thread(task);
thread.start();
thread.join();
task.get();
}
代码示例来源:origin: apache/storm
@Test
public void testConcurrentUnpin() throws Exception {
SimpleWindowPartitionCache<Integer, Object> cache =
SimpleWindowPartitionCache.<Integer, Object>newBuilder()
.maximumSize(1)
.build(key -> new Object());
cache.pinAndGet(1);
FutureTask<Boolean> ft1 = new FutureTask<>(() -> cache.unpin(1));
FutureTask<Boolean> ft2 = new FutureTask<>(() -> cache.unpin(1));
Thread t1 = new Thread(ft1);
Thread t2 = new Thread(ft2);
t1.start();
t2.start();
t1.join();
t2.join();
Assert.assertTrue(ft1.get() || ft2.get());
Assert.assertFalse(ft1.get() && ft2.get());
}
代码示例来源:origin: google/guava
@Override
protected void runTest() throws Throwable {
final Runnable runChosenTest =
new Runnable() {
@Override
public void run() {
runChosenTest();
}
};
final FutureTask<Void> task = new FutureTask<>(runChosenTest, null);
startThread(
new Runnable() {
@Override
public void run() {
task.run();
}
});
awaitUninterruptibly(doingCallLatch);
long hangDelayMillis =
(expectedOutcome == Outcome.HANG)
? EXPECTED_HANG_DELAY_MILLIS
: UNEXPECTED_HANG_DELAY_MILLIS;
boolean hung =
!awaitUninterruptibly(callCompletedLatch, hangDelayMillis, TimeUnit.MILLISECONDS);
if (hung) {
assertEquals(expectedOutcome, Outcome.HANG);
} else {
assertNull(task.get(UNEXPECTED_HANG_DELAY_MILLIS, TimeUnit.MILLISECONDS));
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultExecutor() throws Exception {
ThreadPoolTaskExecutor executor = this.context.getBean("default", ThreadPoolTaskExecutor.class);
assertEquals(1, getCorePoolSize(executor));
assertEquals(Integer.MAX_VALUE, getMaxPoolSize(executor));
assertEquals(Integer.MAX_VALUE, getQueueCapacity(executor));
assertEquals(60, getKeepAliveSeconds(executor));
assertEquals(false, getAllowCoreThreadTimeOut(executor));
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
public String call() throws Exception {
return "foo";
}
});
executor.execute(task);
assertEquals("foo", task.get());
}
内容来源于网络,如有侵权,请联系作者删除!