com.google.common.util.concurrent.AbstractFuture.get()方法的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(56)

本文整理了Java中com.google.common.util.concurrent.AbstractFuture.get()方法的一些代码示例,展示了AbstractFuture.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFuture.get()方法的具体详情如下:
包路径:com.google.common.util.concurrent.AbstractFuture
类名称:AbstractFuture
方法名:get

AbstractFuture.get介绍

[英]The default AbstractFuture implementation throws InterruptedException if the current thread is interrupted during the call, even if the value is already available.
[中]如果当前线程在调用期间被中断,则默认的AbstractFuture实现会抛出InterruptedException,即使该值已经可用。

代码示例

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
@Override
public final V get() throws InterruptedException, ExecutionException {
 return super.get();
}

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
@Override
public final V get(long timeout, TimeUnit unit)
  throws InterruptedException, ExecutionException, TimeoutException {
 return super.get(timeout, unit);
}

代码示例来源:origin: google/guava

@Override
public void run() {
 try {
  future.get();
 } catch (Exception e) {
  // nothing
 }
}

代码示例来源:origin: qunarcorp/qmq

@Override
public List<Message> get() {
  while (true) {
    try {
      return super.get();
    } catch (InterruptedException e) {
      LOGGER.info("ignore interrupt pull");
    } catch (ExecutionException e) {
      return Collections.emptyList();
    }
  }
}

代码示例来源:origin: google/j2objc

@CanIgnoreReturnValue
@Override
public final V get() throws InterruptedException, ExecutionException {
 return super.get();
}

代码示例来源:origin: google/guava

@Override
public void run() {
 while (true) {
  try {
   future.get(0, TimeUnit.SECONDS);
   return;
  } catch (InterruptedException | ExecutionException e) {
   return;
  } catch (TimeoutException e) {
   // do nothing
  } finally {
   completedIteration.countDown();
  }
 }
}

代码示例来源:origin: google/j2objc

@CanIgnoreReturnValue
@Override
public final V get(long timeout, TimeUnit unit)
  throws InterruptedException, ExecutionException, TimeoutException {
 return super.get(timeout, unit);
}

代码示例来源:origin: google/guava

@Override
public void run() {
 startTime = System.nanoTime();
 try {
  future.get(timeout, unit);
 } catch (Exception e) {
  // nothing
  exception = e;
 } finally {
  timeSpentBlocked = System.nanoTime() - startTime;
 }
}

代码示例来源:origin: wildfly/wildfly

@CanIgnoreReturnValue
@Override
public final V get() throws InterruptedException, ExecutionException {
 return super.get();
}

代码示例来源:origin: wildfly/wildfly

@CanIgnoreReturnValue
@Override
public final V get(long timeout, TimeUnit unit)
  throws InterruptedException, ExecutionException, TimeoutException {
 return super.get(timeout, unit);
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
public T get(long timeout, TimeUnit unit)
  throws InterruptedException, TimeoutException, ExecutionException {
 callAsyncGet(timeout, unit);
 return super.get(0, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

@Override
public T get() throws InterruptedException, ExecutionException {
 callAsyncGet(-1, TimeUnit.MILLISECONDS);
 return super.get();
}

代码示例来源:origin: google/guava

@Override
public V get() throws ExecutionException, InterruptedException {
 try {
  super.get();
 } catch (ExecutionException e) {
  rethrow(e);
 }
 throw new AssertionError("Unreachable");
}

代码示例来源:origin: google/guava

private ExecutionException getExpectingExecutionException(AbstractFuture<String> future)
  throws InterruptedException {
 try {
  String got = future.get();
  fail("Expected exception but got " + got);
 } catch (ExecutionException e) {
  return e;
 }
 // unreachable, but compiler doesn't know that fail() always throws
 return null;
}

代码示例来源:origin: google/guava

@Override
 public V get(long timeout, TimeUnit unit)
   throws InterruptedException, ExecutionException, TimeoutException {
  try {
   super.get(timeout, unit);
  } catch (ExecutionException e) {
   rethrow(e);
  }
  throw new AssertionError("Unreachable");
 }
}

代码示例来源:origin: google/guava

public void testGetWithTimeoutDoneFuture() throws Exception {
 AbstractFuture<String> future =
   new AbstractFuture<String>() {
    {
     set("foo");
    }
   };
 assertEquals("foo", future.get(0, TimeUnit.SECONDS));
}

代码示例来源:origin: google/guava

f.get();
final AtomicBoolean ranImmediately = new AtomicBoolean();
f.addListener(

代码示例来源:origin: google/guava

future.get();
} catch (Throwable t) {

代码示例来源:origin: google/guava

public void testEvilFuture_setFuture() throws Exception {
 final RuntimeException exception = new RuntimeException("you didn't say the magic word!");
 AbstractFuture<String> evilFuture =
   new AbstractFuture<String>() {
    @Override
    public void addListener(Runnable r, Executor e) {
     throw exception;
    }
   };
 AbstractFuture<String> normalFuture = new AbstractFuture<String>() {};
 normalFuture.setFuture(evilFuture);
 assertTrue(normalFuture.isDone());
 try {
  normalFuture.get();
  fail();
 } catch (ExecutionException e) {
  assertThat(e).hasCauseThat().isSameAs(exception);
 }
}

代码示例来源:origin: google/guava

public void testToString_notDone() throws Exception {
 AbstractFuture<Object> testFuture =
   new AbstractFuture<Object>() {
    @Override
    public String pendingToString() {
     return "cause=[Because this test isn't done]";
    }
   };
 assertThat(testFuture.toString())
   .matches(
     "[^\\[]+\\[status=PENDING, info=\\[cause=\\[Because this test isn't done\\]\\]\\]");
 try {
  testFuture.get(1, TimeUnit.NANOSECONDS);
  fail();
 } catch (TimeoutException e) {
  assertThat(e.getMessage()).contains("1 nanoseconds");
  assertThat(e.getMessage()).contains("Because this test isn't done");
 }
}

相关文章