【问题标题】:Why ParallelFlux doesnt have collectList() similar to Flux?为什么 ParallelFlux 没有类似于 Flux 的 collectList()?
【发布时间】:2019-05-02 03:13:22
【问题描述】:

Flux 有 collectList(),使用起来非常方便,但是 ParallelFlux 中没有 collectList(),我试图了解在 ParallelFlux 中省略 collectList() 背后的原因。

【问题讨论】:

    标签: project-reactor


    【解决方案1】:

    由于创建 ParallelFlux 是为了在不同的线程中并行运行流,因此执行顺序与第一个流的顺序不同,因此通量没有正确的顺序来收集流。

    -它提供您收集以按照您的规则收集它

    -它为您提供 collectSortedList 以您选择的排序方式收集

    -如果您只是想将其收集为列表并且订单不计量,您可以这样做

      Integer integer[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
        ParallelFlux.from(Flux.fromArray(integer), 4)
                .runOn(Schedulers.parallel())
                .sequential()
                .collectList()
                .subscribe(integer1 -> System.out.println(integer1));
    

    【讨论】:

    • 感谢从 Flux 获取无序列表的解决方法。我想知道为什么 Integer integer[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10、11、12、13、14、15}; ParallelFlux.from(Flux.fromArray(integer), 4) .runOn(Schedulers.parallel()).collectList() 不提供获取无序列表的API
    • 如果你放了.sequencial(),你还会有并行处理的好处吗?因为否则,使用 ParallelFlux 就没有意义了,对吧?
    猜你喜欢
    • 2018-09-22
    • 1970-01-01
    • 2016-07-01
    • 2011-07-16
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 2011-04-21
    • 2018-08-11
    相关资源
    最近更新 更多