本文整理了Java中io.reactivex.Scheduler.shutdown()
方法的一些代码示例,展示了Scheduler.shutdown()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.shutdown()
方法的具体详情如下:
包路径:io.reactivex.Scheduler
类名称:Scheduler
方法名:shutdown
[英]Instructs the Scheduler instance to stop threads, stop accepting tasks on any outstanding Worker instances and clean up any associated resources with this Scheduler.
Implementations should make sure the call is idempotent, thread-safe and should not throw any RuntimeException if it doesn't support this functionality.
[中]指示调度程序实例停止线程,停止接受任何未完成的工作程序实例上的任务,并清理与此调度程序关联的所有资源。
实现应该确保调用是幂等的、线程安全的,如果不支持此功能,则不应该抛出任何RuntimeException。
代码示例来源:origin: ReactiveX/RxJava
/**
* Shuts down the standard Schedulers.
* <p>The operation is idempotent and thread-safe.
*/
public static void shutdown() {
computation().shutdown();
io().shutdown();
newThread().shutdown();
single().shutdown();
trampoline().shutdown();
SchedulerPoolFactory.shutdown();
}
代码示例来源:origin: redisson/redisson
/**
* Shuts down the standard Schedulers.
* <p>The operation is idempotent and thread-safe.
*/
public static void shutdown() {
computation().shutdown();
io().shutdown();
newThread().shutdown();
single().shutdown();
trampoline().shutdown();
SchedulerPoolFactory.shutdown();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void startRace() {
final Scheduler s = new SingleScheduler();
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
s.shutdown();
Runnable r1 = new Runnable() {
@Override
public void run() {
s.start();
}
};
TestHelper.race(r1, r1);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void createIoScheduler() {
final String name = "IoSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createIoScheduler(factory);
RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.io(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void createNewThreadScheduler() {
final String name = "NewThreadSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createNewThreadScheduler(factory);
RxJavaPlugins.setNewThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.newThread(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void createComputationScheduler() {
final String name = "ComputationSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createComputationScheduler(factory);
RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.computation(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void createSingleScheduler() {
final String name = "SingleSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createSingleScheduler(factory);
RxJavaPlugins.setSingleSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.single(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
代码示例来源:origin: akarnokd/RxJava2Interop
@Override
public void shutdown() {
source.shutdown();
}
代码示例来源:origin: ReactiveX/RxJava
s.shutdown();
s.shutdown();
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shutdownRejects() {
final int[] calls = { 0 };
Runnable r = new Runnable() {
@Override
public void run() {
calls[0]++;
}
};
Scheduler s = new SingleScheduler();
s.shutdown();
assertEquals(Disposables.disposed(), s.scheduleDirect(r));
assertEquals(Disposables.disposed(), s.scheduleDirect(r, 1, TimeUnit.SECONDS));
assertEquals(Disposables.disposed(), s.schedulePeriodicallyDirect(r, 1, 1, TimeUnit.SECONDS));
Worker w = s.createWorker();
((ScheduledWorker)w).executor.shutdownNow();
assertEquals(Disposables.disposed(), w.schedule(r));
assertEquals(Disposables.disposed(), w.schedule(r, 1, TimeUnit.SECONDS));
assertEquals(Disposables.disposed(), w.schedulePeriodically(r, 1, 1, TimeUnit.SECONDS));
assertEquals(0, calls[0]);
w.dispose();
assertTrue(w.isDisposed());
}
代码示例来源:origin: akarnokd/RxJava2Interop
@Test
public void startStopNotSupported() {
rx.Scheduler v1Scheduler = mock(rx.Scheduler.class);
io.reactivex.Scheduler v2Scheduler = RxJavaInterop.toV2Scheduler(v1Scheduler);
v2Scheduler.start();
verifyNoMoreInteractions(v1Scheduler);
v2Scheduler.shutdown();
verifyNoMoreInteractions(v1Scheduler);
}
代码示例来源:origin: akarnokd/RxJava2Interop
@Test
public void startStopSupport() {
Scheduler v2Scheduler = mock(Scheduler.class);
rx.Scheduler v1Scheduler = RxJavaInterop.toV1Scheduler(v2Scheduler);
SchedulerLifecycle lc = (SchedulerLifecycle)v1Scheduler;
lc.start();
verify(v2Scheduler).start();
lc.shutdown();
verify(v2Scheduler).shutdown();
}
}
代码示例来源:origin: akarnokd/RxJava2Interop
@Test
public void startStopSupported() {
rx.Scheduler v1Scheduler = mock(rx.Scheduler.class, withSettings().extraInterfaces(SchedulerLifecycle.class));
io.reactivex.Scheduler v2Scheduler = RxJavaInterop.toV2Scheduler(v1Scheduler);
v2Scheduler.start();
((SchedulerLifecycle)verify(v1Scheduler)).start();
v2Scheduler.shutdown();
((SchedulerLifecycle)verify(v1Scheduler)).shutdown();
}
}
代码示例来源:origin: com.github.akarnokd/rxjava2-interop
@Override
public void shutdown() {
source.shutdown();
}
代码示例来源:origin: akarnokd/RxJava2Extensions
private void startStop(Scheduler s) {
s.start();
s.shutdown();
s.shutdown();
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void startRace() {
for (int i = 0; i < 1000; i++) {
final Scheduler s = new ParallelScheduler(2);
s.shutdown();
Runnable r = new Runnable() {
@Override
public void run() {
s.start();
}
};
TestHelper.race(r, r, Schedulers.single());
}
}
代码示例来源:origin: akarnokd/RxJava2Extensions
void cancelledTask(Scheduler s) throws InterruptedException {
try {
Worker w = s.createWorker();
try {
assertFalse(w.isDisposed());
Disposable d = w.schedule(this, 200, TimeUnit.MILLISECONDS);
assertFalse(d.isDisposed());
d.dispose();
assertTrue(d.isDisposed());
Thread.sleep(300);
assertEquals(0, calls.get());
w.dispose();
assertTrue(w.isDisposed());
} finally {
w.dispose();
}
} finally {
s.shutdown();
}
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void delayedNonTracking() {
Scheduler s = new ParallelScheduler(2, false);
try {
for (int i = 0; i < 100; i++) {
Flowable.range(1, 10).hide()
.delay(50, TimeUnit.MILLISECONDS, s)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
} finally {
s.shutdown();
}
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void normalTracking() {
Scheduler s = new ParallelScheduler(2, true);
try {
for (int i = 0; i < 100; i++) {
Flowable.range(1, 10).hide()
.observeOn(s, false, 4)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
} finally {
s.shutdown();
}
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void delayedTracking() {
Scheduler s = new ParallelScheduler(2, true);
try {
for (int i = 0; i < 100; i++) {
Flowable.range(1, 10).hide()
.delay(50, TimeUnit.MILLISECONDS, s)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
}
} finally {
s.shutdown();
}
}
内容来源于网络,如有侵权,请联系作者删除!