本文整理汇总了Java中reactor.core.Disposable.Composite方法的典型用法代码示例。如果您正苦于以下问题:Java Disposable.Composite方法的具体用法?Java Disposable.Composite怎么用?Java Disposable.Composite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.Disposable
的用法示例。
在下文中一共展示了Disposable.Composite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: workerSchedulePeriodically
import reactor.core.Disposable; //导入方法依赖的package包/类
static Disposable workerSchedulePeriodically(ScheduledExecutorService exec,
Disposable.Composite tasks,
Runnable task,
long initialDelay,
long period,
TimeUnit unit) {
PeriodicWorkerTask sr = new PeriodicWorkerTask(task, tasks);
if (!tasks.add(sr)) {
throw Exceptions.failWithRejected();
}
try {
Future<?> f = exec.scheduleAtFixedRate(sr, initialDelay, period, unit);
sr.setFuture(f);
}
catch (RejectedExecutionException ex) {
sr.dispose();
//RejectedExecutionException are propagated up
throw ex;
}
return sr;
}
示例2: testWorkerSchedulePeriodicallyCancelsSchedulerTask
import reactor.core.Disposable; //导入方法依赖的package包/类
@Test
public void testWorkerSchedulePeriodicallyCancelsSchedulerTask() throws Exception {
try(TaskCheckingScheduledExecutor executorService = new TaskCheckingScheduledExecutor()) {
CountDownLatch latch = new CountDownLatch(2);
Disposable.Composite tasks = Disposables.composite();
Disposable disposable = Schedulers.workerSchedulePeriodically(executorService, tasks, () -> {
latch.countDown();
}, 0, 10, TimeUnit.MILLISECONDS);
latch.await();
disposable.dispose();
assertThat(executorService.isAllTasksCancelled()).isTrue();
}
}
示例3: workerSchedule
import reactor.core.Disposable; //导入方法依赖的package包/类
static Disposable workerSchedule(ScheduledExecutorService exec,
Disposable.Composite tasks,
Runnable task,
long delay,
TimeUnit unit) {
WorkerTask sr = new WorkerTask(task, tasks);
if (!tasks.add(sr)) {
throw Exceptions.failWithRejected();
}
try {
Future<?> f;
if (delay <= 0L) {
f = exec.submit((Callable<?>) sr);
}
else {
f = exec.schedule((Callable<?>) sr, delay, unit);
}
sr.setFuture(f);
}
catch (RejectedExecutionException ex) {
sr.dispose();
//RejectedExecutionException are propagated up
throw ex;
}
return sr;
}