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


Java ScheduledExecutorService.submit方法代码示例

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


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

示例1: schedule

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
@Override
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) {
    if (innerSubscription.isUnsubscribed()) {
        return Subscriptions.empty();
    }
    final ScheduledAction scheduledAction = new ScheduledAction(action, operationQueue);
    final ScheduledExecutorService executor = IOSScheduledExecutorPool.getInstance();
    Future<?> future;
    if (delayTime <= 0) {
        future = executor.submit(scheduledAction);
    } else {
        future = executor.schedule(scheduledAction, delayTime, unit);
    }
    scheduledAction.add(Subscriptions.from(future));
    scheduledAction.addParent(innerSubscription);
    return scheduledAction;
}
 
开发者ID:SnowdogApps,项目名称:MoeSampleApp,代码行数:18,代码来源:HandlerThreadScheduler.java

示例2: schedule

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
@Override
public Disposable schedule(final Runnable action, long delayTime, TimeUnit unit) {
    if (innerSubscription.isDisposed()) {
        return Disposables.empty();
    }

    final ScheduledAction scheduledAction = new ScheduledAction(action, operationQueue);
    final ScheduledExecutorService executor = IOSScheduledExecutorPool.getInstance();

    Future<?> future;
    if (delayTime <= 0) {
        future = executor.submit(scheduledAction);
    } else {
        future = executor.schedule(scheduledAction, delayTime, unit);
    }

    scheduledAction.add(Disposables.fromFuture(future));
    scheduledAction.addParent(innerSubscription);

    return scheduledAction;
}
 
开发者ID:devjn,项目名称:RxiOSMOE,代码行数:22,代码来源:HandlerThreadScheduler.java

示例3: submitToPool

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
private void submitToPool() {
    ScheduledExecutorService es;
    if (this.highPriority) {
        es = ThreadManager.getPoolHigh();
    } else {
        es = ThreadManager.getPool();
    }
    es.submit(this);
}
 
开发者ID:BlueYangDroid,项目名称:MvpPlus,代码行数:10,代码来源:AbsThreadTask.java

示例4: testExecuteOnlyOnce

import java.util.concurrent.ScheduledExecutorService; //导入方法依赖的package包/类
/**
 * Test to make sure we only execute the task once no matter how many times we schedule it.
 */
@Test
public void testExecuteOnlyOnce() throws Exception {
  ScheduledExecutorService ex = Executors.newScheduledThreadPool(1);

  MyConflationListener listener = new MyConflationListener();
  OneTaskOnlyExecutor decorator = new OneTaskOnlyExecutor(ex, listener);

  final CountDownLatch latch = new CountDownLatch(1);
  ex.submit(new Callable() {

    public Object call() throws Exception {
      latch.await();
      return null;
    }
  });

  final AtomicInteger counter = new AtomicInteger();

  Runnable increment = new Runnable() {

    public void run() {
      counter.incrementAndGet();
    }
  };

  for (int i = 0; i < 50; i++) {
    decorator.schedule(increment, 0, TimeUnit.SECONDS);
  }

  assertEquals(0, counter.get());
  latch.countDown();
  ex.shutdown();
  ex.awaitTermination(60, TimeUnit.SECONDS);
  assertEquals(1, counter.get());
  assertEquals(49, listener.getDropCount());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:40,代码来源:OneTaskOnlyDecoratorJUnitTest.java


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