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

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

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

ExecutionList.execute介绍

[英]Runs this execution list, executing all existing pairs in the order they were added. However, note that listeners added after this point may be executed before those previously added, and note that the execution order of all listeners is ultimately chosen by the implementations of the supplied executors.

This method is idempotent. Calling it several times in parallel is semantically equivalent to calling it exactly once.
[中]运行此执行列表,按照添加的顺序执行所有现有对。但是,请注意,在此点之后添加的侦听器可能会在先前添加的侦听器之前执行,并且请注意,所有侦听器的执行顺序最终由提供的执行器的实现选择。
这个方法是幂等的。并行调用它几次在语义上等同于只调用它一次。

代码示例

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

/** Internal implementation detail used to invoke the listeners. */
 @Override
 protected void done() {
  executionList.execute();
 }
}

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

/** Internal implementation detail used to invoke the listeners. */
 @Override
 protected void done() {
  executionList.execute();
 }
}

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

/** Internal implementation detail used to invoke the listeners. */
 @Override
 protected void done() {
  executionList.execute();
 }
}

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

@Override
 public void run() {
  list.execute();
 }
};

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

@Override
 public void run() {
  try {
   /*
    * Threads from our private pool are never interrupted. Threads from a
    * user-supplied executor might be, but... what can we do? This is another reason
    * to return a proper ListenableFuture instead of using listenInPoolThread.
    */
   getUninterruptibly(delegate);
  } catch (Throwable e) {
   // ExecutionException / CancellationException / RuntimeException / Error
   // The task is presumably done, run the listeners.
  }
  executionList.execute();
 }
});

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

executionList.execute();
return;

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

@Override
 public void run() {
  try {
   /*
    * Threads from our private pool are never interrupted. Threads from a
    * user-supplied executor might be, but... what can we do? This is another reason
    * to return a proper ListenableFuture instead of using listenInPoolThread.
    */
   getUninterruptibly(delegate);
  } catch (Throwable e) {
   // ExecutionException / CancellationException / RuntimeException / Error
   // The task is presumably done, run the listeners.
  }
  executionList.execute();
 }
});

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

@Override
protected void done() {
 _executionList.execute();
 try {
  shutDown();
 } catch (IOException ioe) {
  _log.error("Failed to close job launcher.");
 }
}

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

@Override
 public void run() {
  try {
   /*
    * Threads from our private pool are never interrupted. Threads from a
    * user-supplied executor might be, but... what can we do? This is another reason
    * to return a proper ListenableFuture instead of using listenInPoolThread.
    */
   getUninterruptibly(delegate);
  } catch (Throwable e) {
   // ExecutionException / CancellationException / RuntimeException / Error
   // The task is presumably done, run the listeners.
  }
  executionList.execute();
 }
});

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

executionList.execute();
return;

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

executionList.execute();
return;

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

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

代码示例来源: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: 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

/**
 * Subclasses should invoke this method to set the result of the computation to an error, {@code
 * throwable}. This will set the state of the future to {@link OldAbstractFuture.Sync#COMPLETED}
 * and invoke the listeners if the state was successfully changed.
 *
 * @param throwable the exception that the task failed with.
 * @return true if the state was successfully changed.
 */
@CanIgnoreReturnValue
protected boolean setException(Throwable throwable) {
 boolean result = sync.setException(checkNotNull(throwable));
 if (result) {
  executionList.execute();
 }
 return result;
}

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

@CanIgnoreReturnValue
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
 if (!sync.cancel(mayInterruptIfRunning)) {
  return false;
 }
 executionList.execute();
 if (mayInterruptIfRunning) {
  interruptTask();
 }
 return true;
}

代码示例来源: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: google/guava

/**
 * Subclasses should invoke this method to set the result of the computation to {@code value}.
 * This will set the state of the future to {@link OldAbstractFuture.Sync#COMPLETED} and invoke
 * the listeners if the state was successfully changed.
 *
 * @param value the value that was the result of the task.
 * @return true if the state was successfully changed.
 */
@CanIgnoreReturnValue
protected boolean set(@Nullable V value) {
 boolean result = sync.set(value);
 if (result) {
  executionList.execute();
 }
 return result;
}

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

/**
  * Internal implementation detail used to invoke the listeners.
  */
 @Override
 protected void done() {
  executionList.execute();
 }
}

代码示例来源:origin: jclouds/legacy-jclouds

private Injector createInjector() {
 Injector i = Guice.createInjector(new AbstractModule() {
   protected void configure() {
    bindConstant().annotatedWith(named(PROPERTY_IO_WORKER_THREADS)).to(1);
    bindConstant().annotatedWith(named(PROPERTY_USER_THREADS)).to(1);
   }
 }, new LifeCycleModule(), new ExecutorServiceModule());
 // TODO: currently have to manually invoke the execution list, as otherwise it may occur
 // before everything is wired up
 i.getInstance(ExecutionList.class).execute();
 return i;
}

相关文章

微信公众号

最新文章

更多