码迷,mamicode.com
首页 > 编程语言 > 详细

Reactor系列(十七)parallel多线程

时间:2020-01-01 11:36:52      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:core   interrupt   sch   ack   mono   package   www   div   tca   

#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分钟视频学习

技术图片

Reactor系列(十七)parallel多线程

标签:core   interrupt   sch   ack   mono   package   www   div   tca   

原文地址:https://www.cnblogs.com/JavaWeiBianCheng/p/12128490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!