我可以运行2个Mono异步反应堆核心吗? [英] Can I run 2 Mono asynchronous Reactor Core?

查看:65
本文介绍了我可以运行2个Mono异步反应堆核心吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中:

    Mono<response> response = mon.just()
    Mono<object> object = mono.just()
    return response.block()

响应和对象彼此不依赖.有没有办法同时并行运行两个Monos?

Response and object are not dependent on each other. Is there a way to run the 2 monos at the same time in parallel?

推荐答案

有不止一种方法.一种简单的解决方案是使用 subscribeOn 运算符:

There is more then one way. One easy solution is to use the subscribeOn operator:

Mono<response> response = Mono.just(...).subscribeOn(Schedulers.elastic());
Mono<object> object = Mono.just(...).subscribeOn(Schedulers.elastic());

只要有人订阅您的Monos,它就会在另一个线程中发生.在这种情况下,线程是从现有池中获取的. Schedulers 提供了多种方法,可让您使用现有线程或创建新线程(请参阅

Whenever someone subscribes to your Monos, it will happen in another thread. In this case the thread is taken from an existing pool. Schedulers offers a variety of methods that allow you to use existing threads or create new ones (see documentation).

如果您对响应流和多线程感兴趣,我最近写了一个文章.

If you are interested in reactive streams and multithreading, I recently wrote an article about it.

这篇关于我可以运行2个Mono异步反应堆核心吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆