Reactor系列(十七)parallel多線程


#java#reactor#flux#parallet#

多線程

視頻解說: https://www.bilibili.com/video/av81386202/

FluxMonoTestCase.java
package com.example.reactor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

@Slf4j
public class FluxMonoTestCase extends BaseTestCase {
    @Test
    public void parllel() throws InterruptedException {
        Flux.range(1,10)
                .parallel()
                .runOn(Schedulers.parallel())
                .subscribe(x ->log.info("->{}",x));
    }
}

結果:

11:03:33.472 [main] DEBUG reactor.util.Loggers$LoggerFactory - Using Slf4j logging framework
11:03:33.509 [parallel-8] INFO com.example.reactor.FluxMonoTestCase - ->8
11:03:33.509 [parallel-6] INFO com.example.reactor.FluxMonoTestCase - ->6
11:03:33.509 [parallel-4] INFO com.example.reactor.FluxMonoTestCase - ->4
11:03:33.508 [parallel-1] INFO com.example.reactor.FluxMonoTestCase - ->1
11:03:33.508 [parallel-3] INFO com.example.reactor.FluxMonoTestCase - ->3
11:03:33.508 [parallel-2] INFO com.example.reactor.FluxMonoTestCase - ->2
11:03:33.514 [parallel-1] INFO com.example.reactor.FluxMonoTestCase - ->9
11:03:33.509 [parallel-5] INFO com.example.reactor.FluxMonoTestCase - ->5
11:03:33.514 [parallel-2] INFO com.example.reactor.FluxMonoTestCase - ->10
11:03:33.509 [parallel-7] INFO com.example.reactor.FluxMonoTestCase - ->7

公眾號,堅持每天3分鍾視頻學習


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM