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

x33g5p2x  于2022-01-19 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(77)

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

ExecutionList.add介绍

[英]Adds the Runnable and accompanying Executor to the list of listeners to execute. If execution has already begun, the listener is executed immediately.

When selecting an executor, note that directExecutor is dangerous in some cases. See the discussion in the ListenableFuture#addListenerdocumentation.
[中]将可运行和伴随的执行器添加到要执行的侦听器列表中。如果执行已经开始,侦听器将立即执行。
选择执行器时,请注意directExecutor在某些情况下是危险的。请参阅ListenableFuture#AddListener文档中的讨论。

代码示例

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);
}

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);
}

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);
}

代码示例来源:origin: apache/incubator-gobblin

@Override
public void addListener(Runnable listener, Executor executor) {
 _executionList.add(listener, executor);
}

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

/**
 * {@inheritDoc}
 *
 * @since 10.0
 */
@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);
}

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);

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

public void testExceptionsCaught() {
 list.add(THROWING_RUNNABLE, directExecutor());
 list.execute();
 list.add(THROWING_RUNNABLE, directExecutor());
}

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);

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

public void testRunOnPopulatedList() throws Exception {
 Executor exec = Executors.newCachedThreadPool();
 CountDownLatch countDownLatch = new CountDownLatch(3);
 list.add(new MockRunnable(countDownLatch), exec);
 list.add(new MockRunnable(countDownLatch), exec);
 list.add(new MockRunnable(countDownLatch), exec);
 assertEquals(3L, countDownLatch.getCount());
 list.execute();
 // Verify that all of the runnables execute in a reasonable amount of time.
 assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}

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

@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);

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

public void testOrdering() throws Exception {
 final AtomicInteger integer = new AtomicInteger();
 for (int i = 0; i < 10; i++) {
  final int expectedCount = i;
  list.add(
    new Runnable() {
     @Override
     public void run() {
      integer.compareAndSet(expectedCount, expectedCount + 1);
     }
    },
    MoreExecutors.directExecutor());
 }
 list.execute();
 assertEquals(10, integer.get());
}

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

public void testAddAfterRun() throws Exception {
 // Run the previous test
 testRunOnPopulatedList();
 // If it passed, then verify an Add will be executed without calling run
 CountDownLatch countDownLatch = new CountDownLatch(1);
 list.add(new MockRunnable(countDownLatch), Executors.newCachedThreadPool());
 assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}

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

public void testExecute_idempotentConcurrently() throws InterruptedException {
 final CountDownLatch okayToRun = new CountDownLatch(1);
 final AtomicInteger runCalled = new AtomicInteger();
 list.add(
   new Runnable() {
    @Override

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

public void testExecute_idempotent() {
 final AtomicInteger runCalled = new AtomicInteger();
 list.add(
   new Runnable() {
    @Override
    public void run() {
     runCalled.getAndIncrement();
    }
   },
   directExecutor());
 list.execute();
 assertEquals(1, runCalled.get());
 list.execute();
 assertEquals(1, runCalled.get());
}

代码示例来源:origin: com.yahoo.vespa/component

/** Adds a listener which will be invoked when this has become frozen. */
@Override
public void addFreezeListener(Runnable runnable, Executor executor) {
  executionList.add(runnable,executor);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/**
 * {@inheritDoc}
 *
 * @since 10.0
 */
@Override
public void addListener(Runnable listener, Executor exec) {
 executionList.add(listener, exec);
}

代码示例来源:origin: prestosql/presto

@Override
public void addListener(Runnable listener, Executor executor)
{
  executionList.add(listener, executor);
}

代码示例来源:origin: com.google.guava/guava-tests

public void testRunOnPopulatedList() throws Exception {
 Executor exec = Executors.newCachedThreadPool();
 CountDownLatch countDownLatch = new CountDownLatch(3);
 list.add(new MockRunnable(countDownLatch), exec);
 list.add(new MockRunnable(countDownLatch), exec);
 list.add(new MockRunnable(countDownLatch), exec);
 assertEquals(3L, countDownLatch.getCount());
 list.execute();
 // Verify that all of the runnables execute in a reasonable amount of time.
 assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}

代码示例来源:origin: com.google.guava/guava-tests

public void testAddAfterRun() throws Exception {
 // Run the previous test
 testRunOnPopulatedList();
 // If it passed, then verify an Add will be executed without calling run
 CountDownLatch countDownLatch = new CountDownLatch(1);
 list.add(new MockRunnable(countDownLatch),  Executors.newCachedThreadPool());
 assertTrue(countDownLatch.await(1L, TimeUnit.SECONDS));
}

代码示例来源:origin: com.google.guava/guava-tests

public void testExecute_idempotent() {
 final AtomicInteger runCalled = new AtomicInteger();
 list.add(new Runnable() {
  @Override public void run() {
   runCalled.getAndIncrement();
  }
 }, directExecutor());
 list.execute();
 assertEquals(1, runCalled.get());
 list.execute();
 assertEquals(1, runCalled.get());
}

相关文章

微信公众号

最新文章

更多