當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。