第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

具有匿名線程的反應(yīng)器調(diào)度程序

具有匿名線程的反應(yīng)器調(diào)度程序

慕尼黑5688855 2022-05-12 17:16:04
我正在測試 reactor 的工作原理,創(chuàng)建了與 reactor 文檔中的代碼非常相似的代碼。import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import reactor.core.publisher.Mono;import reactor.core.scheduler.Scheduler;import reactor.core.scheduler.Schedulers;@SpringBootTest@RunWith(SpringRunner.class)public class ReactorApplicationTests {  @Test  public void publishOnThreadTest() {    Scheduler s = Schedulers.newParallel("parallel-scheduler", 4);    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(System.out::println)).start();  }}我不能讓它運(yùn)行,我做錯(cuò)了什么?只需訂閱它就可以工作,但我想看看使用的線程并玩一下它。
查看完整描述

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();

}


查看完整回答
反對(duì) 回復(fù) 2022-05-12
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)