1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的測試程序什么也不打印的原因是它退出得太早了。它應(yīng)該等到調(diào)用 substriber 的方法:
@Test
public void publishOnThreadTest() throws InterruptedException {
Scheduler s = Schedulers.newParallel("parallel-scheduler", 4);
CountDownLatch latch = new CountDownLatch(1);
final Mono<String> mono = Mono.just("Publish on test: \n")
.map(msg -> msg + "before: " + Thread.currentThread() )
.publishOn(s)
.map(msg -> msg + "\nafter: " + Thread.currentThread());
new Thread(() -> mono.subscribe((String str) ->{
System.out.println(str);
latch.countDown();
})).start();
latch.await();
}
添加回答
舉報(bào)