简体   繁体   English

RxJava在线程方面实际上如何在内部工作?

[英]How does RxJava actually work internally in regards to threading?

I have experience working with RxJava, to make reactive applications. 我有使用RxJava进行响应式应用程序的经验。 However, I'm wondering how it (and other libraries, like Spring Reactor), actually work on the inside. 但是,我想知道它(以及其他库,例如Spring Reactor)如何在内部实际工作。 I can't seem to find any interesting information regarding that online, only the typical simple tutorials. 我似乎在网上找不到任何有关该有趣的信息,只有典型的简单教程。 How does it deal with threading, etc? 它如何处理线程等? Do all "actors" run on the same thread? 所有“角色”都在同一线程上运行吗? Or is it a thread per "declaration"? 还是每个“声明”都有线程?

One key point about RxJava is it allows both the API owner and the consumer to decide on an execution model (and change it without breaking any interfaces). 关于RxJava的一个关键点是,它允许API所有者和使用者都确定执行模型(并在不破坏任何接口的情况下对其进行更改)。 If you want to expose an observable which runs on the calling subscriber thread, inside an ExecutorService , on an Actor, etc, that's up to you. 如果要公开在主叫方线程, ExecutorService内部,Actor等上运行的ExecutorServiceExecutorService您决定。 Likewise you can subscribe to an observable using whatever threading model suits- be it blocking on the calling thread or on some kind of thread pool. 同样,您可以使用任何适合的线程模型来订阅一个可观察对象-它阻塞在调用线程或某种线程池上。 Bottom line is the library itself takes no opinion on threading model; 底线是自己承担的线程模型没有意见库; you need to decide what's best for the workload you're exposing. 您需要确定最适合暴露的工作负载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM