本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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());
}