当前位置: 首页>>代码示例>>Java>>正文


Java ListenableFuture.addListener方法代码示例

本文整理汇总了Java中org.threadly.concurrent.future.ListenableFuture.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java ListenableFuture.addListener方法的具体用法?Java ListenableFuture.addListener怎么用?Java ListenableFuture.addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.threadly.concurrent.future.ListenableFuture的用法示例。


在下文中一共展示了ListenableFuture.addListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeOrQueue

import org.threadly.concurrent.future.ListenableFuture; //导入方法依赖的package包/类
/**
 * This is called once a task is ready to be executed (or if unable to execute immediately, 
 * queued).  In addition to the task itself, this function takes in any future which represents 
 * task execution (if available, otherwise {@code null}).  Passing in as a separate argument 
 * allows us to avoid a {@code instanceof} check, but does require it to be specified for 
 * pre-future listener completion support.
 * 
 * @param task Task to be executed
 * @param future Future to represent task completion or {@code null} if not available
 */
protected void executeOrQueue(Runnable task, ListenableFuture<?> future) {
  if (limitFutureListenersExecution || future == null) {
    executeOrQueueWrapper(new LimiterRunnableWrapper(task));
  } else {
    // we will release the limit restriction as soon as the future completes.
    // listeners should be invoked in order, so we just need to be the first listener here
    // We add a `SameThreadSubmitterExecutor` so that we get executed first as if it was async
    future.addListener(this::releaseExecutionLimit, SameThreadSubmitterExecutor.instance());

    if (canRunTask()) {
      executor.execute(task);
    } else {
      addToQueue(new TransparentRunnableContainer(task));
    }
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:27,代码来源:ExecutorLimiter.java

示例2: listenableFutureTest

import org.threadly.concurrent.future.ListenableFuture; //导入方法依赖的package包/类
@Test
public void listenableFutureTest() {
  PriorityScheduler executor = new StrictPriorityScheduler(1);
  try {
    PrioritySchedulerServiceWrapper wrapper = new PrioritySchedulerServiceWrapper(executor);
    TestRunnable futureListener = new TestRunnable();
    ListenableFuture<?> future = wrapper.submit(DoNothingRunnable.instance());
    future.addListener(futureListener);
    
    futureListener.blockTillFinished(); // throws exception if never called
  } finally {
    executor.shutdownNow();
  }
}
 
开发者ID:threadly,项目名称:threadly,代码行数:15,代码来源:PrioritySchedulerServiceWrapperTest.java


注:本文中的org.threadly.concurrent.future.ListenableFuture.addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。