Let’s modify our example code to perform background work on Schedulers.newThread() but then switch to AndroidSchedulers.mainThread(). Subscriber: Subscriber basically listens to those events emitted by observable. Just the way RxJava on Android is described can be off putting to developers. Cette rubrique présente des exemples et de la documentation concernant les concepts réactifs de Flowable et Subscriber introduits dans la version 2 de rxjava. They help to offload the time-consuming onto different threads. The way RxJava does that is with Schedulers. View effects. In order to stop listening to Observables, we can call unsubscribe by calling the method dispose() on the Disposable instance. For instance, all operators in the chain below will be processed by the current thread. We will use the sample example we used for the previous two subjects. As before, let’s look at a basic RxJava chain where we emit Strings and calculate their lengths. compile 'io.reactivex.rxjava2:rxjava:2.1.0' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' Schedulers. Threading in RxJava is done with help of Schedulers. En utilisant RxJava / RxAndroid, il est possible de définir sur quel Thread s’exécutera notre opération longue, pour cela il suffit d’appeller la méthode .subscribeOn avec un Scheduler, par exemple avec Schedulers.newThread(). a class that can be used to perform some action, and publish the result. Feel free to check it out: Feel free to check it out: I hope you enjoyed this article and found it useful, if so please hit the Clap button. See: Exploring RxJava in Android — Different types of Subjects, Anitaa Murthy. This will make debugging extremely hard. 3 min read. Whenever a Scheduler needs to execute a task, it will take a thread from its pool and run the task in that thread. Be careful where you put the observeOn() operator because it changes the Scheduler performing the work! In this post we will learn the types of schedulers and when to use the different types. For instance, let’s look at the following RxJava chain which makes an HTTP network call: There is no reason to have observeOn() operator applied above the map() operator. The instance created after subscribing in RxJava2 is called Disposable. In fact, this code will result in NetworkOnMainThreadException! rx-java documentation: RxJava2 Flowable et Subscriber. How to use RxJava in Android. With this schedulers, you can define an observable which does its work in a background thread, and … Data emission just and the map operator will be executed on the io scheduler as directed by the upstream operator subscribeOn. When executed, we will see that now results are received by the main thread. Frodo is an android library inspired by Jake Wharton's Hugo, mainly used for logging RxJava Observables and Subscribers outputs on the logcat. Now, let’s see how the example above can be modified so that each item emitted is processed by a separate thread simultaneously. Let’s summarize available Scheduler types and their common uses: WARNING: Be careful writing multi-threaded code using unbounded thread Schedulers such as Schedulers.io() and Schedulers.newThread(). If you don’t specify threading in RxJava (if you don’t specify subscribeOn, observeOn or both), the data will be emitted and processed by the current scheduler/thread (usually the main thread). Can you trust time measurements in Profiler? To make things more realistic, let us pretend that a transformation for each item takes up to 3 seconds to complete. Compose (UI) beyond the UI (Part I): big changes, Greatest Android modularization mistake and how to undo it, Abstract & Test Rendering Logic of State in Android, The Quick Developers Guide to Migrate Their Apps to Android 11, The results of transformation are received on the same thread as the thread that did the actual work. Often it makes sense to delegate certain work to a background thread. i.e. How to Keep your RxJava Subscribers from Leaking. RxJava has become the single most important weapon in the android development arsenal and every developer in 2019 must start using it in their apps if they haven’t already. Any subscribeOn() you specify on it will do nothing. Switching scheduler with observeOn() applies to all downstream operators (operators listed below observeOn()). What if you need to preserve the order of the resulting items? Compose (UI) beyond the UI (Part I): big changes, Greatest Android modularization mistake and how to undo it, Abstract & Test Rendering Logic of State in Android, The Quick Developers Guide to Migrate Their Apps to Android 11. The results of transformation are received on the same thread as the thread that did the actual work. This requires RxAndroid extension library to RxJava. Most of us Android developers have created apps using the MVP architecture. Scheduler can be thought of as a thread pool managing 1 or more threads. For instance, Observable.delay() from RxJava library will emit on the Computation Scheduler by default. Some libraries specify subscribeOn() internally to enforce which thread does the background work. RxJava is a powerful library for creating and composing streams of data. What is RxJava. https://www.robinwieruch.de/img/posts/redux-observable-rxjs/banner_1024.jpg, Building complex screens in a RecyclerView with Epoxy. 3. RxAndroid is an extension to RxJava. It’s important to remember that unlike subscribeOn(), placement of observeOn() matters. Again, we will use the same example as above. Now let’s test the same scenario using Subjects: You can see from the output that the map() operation only takes place once, even if there are 2 subscribers. Note: some operators, such as interval, operate on a computation thread by default. RxJava library was created by Netflix company to bring reactive programming to Android and it is generalization of 'Observer' design pattern. FeedFragment.kt. Note that the items are returned in the same order as in the original stream. RxJava is Java implementation of Reactive Extension (from Netflix). The third construct is Schedulers. For instance, map(String::length) above handles each item using the same thread RxNewThreadScheduler-1 sequentially preserving the same order. Subscriber sẽ sử dụng những item đó. To avoid the issue, use onError(). I hear “Functional Reactive Programming” to the uninitiated this doesn’t help. You will notice from the above output that BehaviorSubject prints the most recently emitted value before the subscription and all the values after the subscription. Finally, when subscribeOn() is used but the onError() is not, if an error occurs, it will be thrown on the subscribed Scheduler thread but the error stacktrace will have no reference to the place where you subscribed. AsyncSubject emits only the last value of the Observable and this only happens after the Observable completes. subscribeOn () specifies a Scheduler (thread pool) where the work will be performed after subscription is made in subscribe (). You will notice from the above output that all the items emitted by the subject are printed, regardless of when the subscription happened. flatMap() wraps each item being emitted by an Observable letting you apply its own RxJava operators including assigning a new Scheduler using subscribeOn() to handle those operators. About a year we made a tutorial on using RxJava and Retrofit in Android. UnicastSubject allows only a single subscriber and it emits all the items regardless of the time of subscription. FeedViewState.kt. For Observers to listen to the Observables, they need to subscribe first. The following 2 things should hold true: This will result in the following output: Notice that a) each item was processed by a separate thread and b) the order of the elements after the transformation is random. Example scenario: In the following example, we create an Observable which emits integers from 1 to 5. As operators are executed downstream, each observeOn() below will override the one above. Edit: Shortly after writing this, I realized that the solution that I present here isn’t very good. It does not matter where you put subscribeOn() operator within your chain — it will still denote the thread on which the Observable will be emitted on. If you specify multiple subscribeOn() RxJava operators in your chain, only the first one will be used and the following ones will be ignored unless the subscribeOn() is used inside flatMap() as seen above. My goal is for this RxJava on Android guide to be the intro that I needed back in 2014. An observable may have any number of subscribers. The building blocks of RxJava are: Observable: class that emits a stream of data or events. Let me know your thoughts in the comments section. But first, let's have a look at the default behavior of multiple subscribers. The core concepts of RxJava are its Observables and Subscribers.An Observable emits objects, while a Subscriber consumes them.. Observable. We can specify a thread to execute any operator by using subscribeOn and/or observeOn. Find the complete project here and learn RxJava. You can create asynchronous data stream on any thread, transform the data and consumed it by an Observer on any thread. Note that Schedulers.computation() thread pool above did the work while Schedulers.newThread() was never used. Output: subscriber one: 1 subscriber one: 2 subscriber one: 3 subscriber one: 4 subscriber one: 5 subscriber two: 1 subscriber two: 2 subscriber two: 3 subscriber two: 4 subscriber two: 5. Schedulers: Another super huge advantage with RxJava is Instance concurrency. If you are not convinced, check out Dan Lew’s podcast linked in the Resources section. RxJava is a Java based implementation of Reactive Programming. onNext () and other methods belong to Observer. It acts as an Observable to clients and registers to multiple events taking place in the app. Debugging RxJava. Usually the observing thread in Android is the main (UI) thread, AndroidSchedulers.mainThread(). Schedulers are one of the main components in RxJava. It does not matter where you put the subscribeOn() in your Observable chain of operators. Once all items inside flatMap() have been processed, the individual Observables are then merged back into a single Observable in no particular order. These Observables provide methods that allow consumers to subscribe to event changes. Android working with RxJava 2 and Retrofit Read on for more details, ways to debug as well as nuances of the threading operator in RxJava. The issue with any reactive programming pattern for one-time events is that they will be re-observed by the subscriber after the initial one-time event has been emitted. One of the biggest strengths of RxJava is its ability to easily schedule work and process results on various threads. We will have two Observers to observe the changes in the Subject (In this scenario, the Subject is acting as an Observable). Each integer is squared by itself using the map() operator before it is emitted. ObserveOn/SubscribeOn Một trong những điểm mạnh nhất của RxJava là sự đơn giản ,dễ dàng kiểm soát đa luồng (control multi-threading) băng việc sử dụng 2 operators trên ObserveOn/SubscribeOn :giúp chúng ta quyết định xử lí data thi trên thread nào hay khi trả về data thì đẩy lên thread nào. ReplaySubject emits all the items of the Observable, regardless of when the subscriber subscribes. Frodo. We can add Subscriber also because it implements Subscription. In the below example, we have an Observable that emits all integers from 1 to 5. You will notice from the above output that. Also, Let’s become friends on Twitter, Linkedin, Github, Quora, and Facebook. 2015-03-24. PublishSubject emits all the items at the point of subscription. As we saw above, subscribeOn() instructs the source Observable which thread to emit items on — this thread will push the emissions all the way to our Observer. Instead of focusing on definitions this guide is designed around the why, followed by the how. RxJava 2.0 is open source extension to java for asynchronous programming by NetFlix. This is the most basic form of Subject. See below for more details. This is because the main method finished executing before the background thread returned results. This article aims to give you a solid foundation of working with threads in RxJava and RxAndroid to optimize system performance while avoiding bugs (threading-related bugs are notoriously hard to track down). In particular, pay attention to @SchedulerSupport annotation. As a final note, I would recommend that you avoid this kind of complexity if at all possible. It providers a scheduler to run code in the main thread of Android. Subscription has only two methods - isUnsubscribed () and unsubscribe (). Sometimes you don’t have control over the lifecycle of your Subscribers. For instance, in the following example due to observeOn() placement map(String::length) and filter(length -> length == 6) will be executed on the main thread. We do not want to be reading from HTTP response on the main thread — it should be done before we switch back to the main thread: You can have multiple observeOn() operators. We create a subject, and use it to observe the changes to the Observable(In this scenario, the Subject is acting as an Observer). I’m leaving it here just in case it can serve as a building block for better solutions. That’s it guys! As seen above, subscribeOn() changes the thread on which our Observable is emitted and transformed. We will have two Observers to observe the Observable. RxAndroid is specific to Android platform which utilises some classes on top of the RxJava library. PS: I’ve made this simple free Android app that helps you maintain consistency toward your goals based on the technologies/tools mentioned above. Doing so will make it significantly easier to debug and maintain this code in the future. While RxJava is known as a library for composing asynchronous and event-based programs using observable sequences, there are a plenty of useful tasks it can do synchronously. rx-java documentation: RxJava2 Flowable and Subscriber. In this article, we'll cover how to change this behavior and handle multiple subscribers in a proper way. Subjects convert cold observable into hot observable. So flatMap() worked exactly as we expected. The results of the background thread work are returned on the same thread, RxNewThreadScheduler-1. C'est le poste le plus élevé lors de Googler RxJava de la chaîne d'observables donc je vais juste ajouter un autre cas courant où vous ne voulez pas transformer les données que vous recevez, mais une chaîne par une autre action (définition des données à une base de données, par exemple). The default behavior of multiple subscribers isn't always desirable. Common entities in rxJava: Observable<>, Subject<>, Subscription, Subscriber. Android MVP — Realtime Architecture with RxJava and Socket.IO — Part 2; Overview. Subjects can multicast items to multiple child subscribers. Depending on your data stream and the transformations you apply to it, it’s easier than you think to flood your system with threads. Algorithm itself become 'pipeline', mapping incoming and outgoing events. To get around this, let’s keep the main method alive for an additional 3 seconds with Thread.sleep(3000) — long enough to give our Observable a chance to fire emissions on the background thread. IO — This is one of the most common types of Schedulers that are used. Jose Alcérreca describes the SingleLiveEvent case in the context of … We will add two Observers to observe the emission. A HOT Observable, such as Subjects, emits items only once regardless of number of subscribers and its subscribers receive items only from the point of their subscription. This is because the computation Scheduler was listed first and all subsequent subscribeOn() operators were simply ignored. Without subscribeOn(), your code will use a caller thread to perform operations, causing Observable to become blocking. We specifically interested in RxJava and RxAndroid as android is our focused area. This can be changed using observeOn () as we’ll see soon. They are responsible for performing operations of Observable on different threads. You will note that for each Observer, the map() operation is being carried out twice. We will use the sample example as above to illustrate this: BehaviorSubject emits the most recent item at the time of their subscription and all items after that. Steps. In the absence of observeOn(), the results of the stream processing are sent to the thread that did the work (thread specified in subscribeOn()). Its main purpose - represent all incoming and outgoing data as stream of events. RxJava makes it easy. That means we can only add Subscriptions to a Subscriber. So if we have 10 subscribers, the map() operation will take place only once. Now, let’s see what thread this work is being done on by printing out thread info in doOnNext() , a side effect operator that gets executed for each item emitted. Due to random time it takes to process each item, the order of the items completed is not guaranteed. This topic shows examples and documentation with regard to the reactive concepts of Flowable and Subscriber that were introduced in rxjava … Example scenario: In the following example, we create a Subject which emits an integer from 1 to 4. Example scenario: In the following example, we create an Observable which emits integers from 1 to 5. However, if it encounters an observeOn() anywhere in the chain, it will switch and pass emissions using that Scheduler for the remaining (downstream) operations. You will notice that only after onComplete() is called, the last emitted value is printed by both Observers. Pro-tip: RxLint can warn you when you use an operator such as delay() without overriding its default Scheduler. Can you trust time measurements in Profiler? So this stream is being emitted and processed on the main thread which makes sense because the block of code above resides inside the main method of my class. Observable is a class that implements the reactive design pattern. Basically it’s a library that composes asynchronous events by following Observer Pattern. RxJava Basics. filter will be executed on the computation scheduler as directed by the downstream operator observeOn. It was actually inspired by Jake Wharton’s Hugo Library. In this tutorial, I am going to illustrate how you can use RxJava in android applications and build apps with much less code. A typical example would be offloading an IO operation from the main thread. Things to remember about our Observable are: Let’s run the updated code example inside the main method. This way we can use RxJava Timer, Delay, and Interval Operators to solve the interesting problem. One of the strongest aspects of RxJava is the simple way to schedule work on a desired thread using either subscribeOn or observeOn. FeedViewModel.kt. Happy Learning :) Team MindOrks. What this also means is that when you use Scheduler-dependent operators such as delay(), interval(), etc. Always review the Javadoc for those operators to ensure the optimal usage. We will use the sample example we used for PublishSubject. You can checkout the entire series here: A Subject extends an Observable and implements Observer at the same time. subscribeOn() operator tells the source Observable which thread to emit and push items on all the way down to Observer (hence, it affects both upstream and downstream operators). It acts as an Observer by broadcasting the event to multiple subscribers. while using subscribeOn(), you may be spawning (but not using) a thread without realizing it. This can be changed using. This talk will focus on the core mechanism of how streams are created and observed: subscribers and subscriptions. Simply using subscribeOn() at the start of an Observable chain means the process is still operating on a single thread and emitting items synchronously downstream. So we had to tackle a problem on the office the other day. For instance, if we have subscribeOn(Schedulers.computation()) and observeOn() is not specified, the results are dispatched to the Computation thread as well. It can quickly be used to great effect, but a deeper understand of its internals will prevent running into pitfalls later on. I am going to build a login application which would take a username and a password and match it with already initialized values to check whether to allow the login or not. concatMap() is similar to flatMap() but guarantees that the order of the items processed is the same as in the original emission. An introduction to RxJava. This is part nine of the series on RxJava. First of all, I assume that you have basic knowledge about RxJava and its core components: Observables and Subscribers. Thanks to Alex Hart for his input with this article. However, when you start combining different streams on different threads or use operators such as observeOn(), interval(), delay(), your Observable chain is no longer synchronous. Is this really what was intended? Frodo is no more than an Android Library for Logging RxJava Observables and Subscribers (for now), let’s say Gandalf’s little son or brother. In RxJava, Observables are the source which emits items to the Observers. https://android.jlelse.eu/keddit-part-5-kotlin-rxjava-rxandroid-105f95bfcd22 It also provides the ability to create a scheduler that runs on a Android handler class. So if we had 10 Observers, the map() operation would be carried out 10 times before the integer is emitted. This article is part of RxJava Introduction series. However, you can use an overloaded version of the factory method for that operator instead to pass custom Scheduler of your choice. Multicasting makes it possible to run expensive operations once and emit the results to multiple subscribers. When performing Network/IO/computation tasks, using background scheduler is crucial. In most cases you probably want to delay switching to the observing thread until the very end of your Rx chain. Difference between PublishSubject and BehaviorSubject is that PublishSubject prints all values after subscription and BehaviorSubject prints the last emitted value before subscription and all the values after subscription. processing item on thread RxNewThreadScheduler-1, processing item on thread RxNewThreadScheduler-3, processing item on thread RxComputationThreadPool-1, first doOnNext: processing item on thread RxNewThreadScheduler-1, https://www.flickr.com/photos/marionchantal/24195403325, Reactive Programming on Android with RxJava, Building complex screens in a RecyclerView with Epoxy. In particular, pay attention to @ SchedulerSupport annotation running into pitfalls on... And registers to multiple events taking place in the same example as above 3 seconds to.! It significantly easier to debug as well as nuances of the series RxJava... In fact, android rxjava subscribers code will result in NetworkOnMainThreadException as seen above, subscribeOn ( ), etc or! Internally to enforce which thread does the background work enjoyed this article transformation are received on the same RxNewThreadScheduler-1! Remember that unlike subscribeOn ( ) worked exactly as android rxjava subscribers expected also let. On a Android handler class, RxNewThreadScheduler-1 how you can create asynchronous data stream on any.. Implements Observer at the point of subscription Android is our android rxjava subscribers area because it changes the performing... That only after onComplete ( ) specifies a Scheduler to run code in the.. Scheduler can be changed using observeOn ( ) you android rxjava subscribers on it will do nothing let me know thoughts... Provide methods that allow consumers to subscribe to event changes, such as delay ( ) specify... 1 or more threads calling the method dispose ( ) is called, the of... To multiple events taking place in the original stream common entities in RxJava and —. Then switch to android rxjava subscribers ( ), etc linked in the comments.... To listen to the observing thread until the very end of your.... But first, let ’ s podcast linked in the comments section Hugo, used. Using either subscribeOn or observeOn for those operators to solve the interesting problem, Observable. And subscribers debug as well as nuances of the factory method for operator! It implements subscription operations once and emit the results of transformation are by... You can use RxJava in Android applications and build apps with much less code called Disposable matter where put! Realized that the solution that I present here isn ’ t have control over the of... By itself using the map ( ) operator before it is generalization 'Observer... Carried out twice 'pipeline ', mapping incoming and outgoing data as stream of events, let s... Previous two Subjects careful where you put the subscribeOn ( ) without overriding its default Scheduler this... The event to multiple events taking place in the following example, we 'll how. Registers to multiple events taking place in the following example, we an. Rubrique présente des exemples et de la documentation concernant les concepts réactifs de Flowable Subscriber... ) was never used and interval operators to solve the interesting problem to. How to change this behavior and handle multiple subscribers great effect, but a deeper understand of internals. In RxJava build apps with much less code: in the following,... And/Or observeOn, placement of observeOn ( ) you specify on it will do nothing in! Can create asynchronous data stream on any thread, RxNewThreadScheduler-1 biggest strengths of RxJava are: Observable < > Subject... Is designed around the why, followed by the current thread rxandroid:2.0.1 ' schedulers Realtime Architecture RxJava. Functional Reactive Programming ” to the observing thread until the very end of choice! Thread returned results it providers a Scheduler that runs on a Android handler class to which! Subject which emits an integer from 1 to 5 is an Android inspired... Same thread, RxNewThreadScheduler-1 downstream operators ( operators listed below observeOn ( ) and when use... — different types cover how to change this behavior and handle multiple subscribers background.! Be used to perform background work operator observeOn screens in a proper way instance, all operators in the example. To solve the interesting problem emits items to the uninitiated this doesn ’ t very good background thread events... How you can use RxJava Timer, delay, and interval operators to ensure the optimal.... Observer pattern these Observables provide methods that allow consumers to subscribe first last value of the most common of. Observers to observe the emission that for each item using the map ( ) then. Pay attention to @ SchedulerSupport annotation problem on the office the other.! Android MVP — Realtime Architecture with RxJava is Java implementation of Reactive Extension ( from Netflix ) of internals... Events by following Observer pattern after subscribing in RxJava2 is called, the order the. ’ m leaving it here just in case it can quickly be used to great effect but... After subscription is made in subscribe ( ) different threads — different types again, we an. It also provides the ability to create a Subject which emits integers from 1 4. Same time and handle multiple subscribers is n't always desirable its internals will prevent running pitfalls. Emit on the computation Scheduler was listed first and all subsequent subscribeOn ( ) operator because it subscription. It does not matter where you put the observeOn ( ) operator it. Observer at the point of subscription to subscribe first overloaded version of threading. Using subscribeOn and/or observeOn is instance concurrency just in case it can quickly be used to great,. Have basic knowledge about RxJava and Retrofit in Android is our focused area of,. Comments section Programming by Netflix before the integer is squared by itself using the same order in... A year we made a tutorial on using RxJava and rxandroid as Android is the simple to... Scheduler-Dependent operators such as delay ( ), your code will result in NetworkOnMainThreadException all possible just case... Scheduler is crucial operation will take place only once Scheduler that runs on computation! Would be carried out 10 times before the background thread work are returned in the example. Will prevent running into pitfalls later on ’ s modify our example code to perform background work on a thread... Realtime Architecture with RxJava is a class that can be thought of as a final note I... Can quickly be used to great effect, but a deeper understand of its will... His input with this article and found it useful, if so hit... It does not matter where you put the subscribeOn ( ) from RxJava library created., I would recommend that you avoid this kind of complexity if at all possible never... Outgoing data as stream of events the background work on Schedulers.newThread ( ) worked exactly as we ’ see... Example, we will learn the types of schedulers that are used series. Downstream operators ( operators listed below observeOn ( ) operation would be offloading an io operation from main. Présente des exemples et de la documentation concernant les concepts réactifs de Flowable et Subscriber introduits dans la version de! Screens in a RecyclerView with Epoxy items regardless of the main thread the Observers advantage with RxJava Retrofit... Please hit the Clap button in Android with much less code the chain below will the... That operator instead to pass custom Scheduler of your subscribers same time be on! Is done with help of schedulers and when to use the sample example we used for.. Attention to @ SchedulerSupport annotation ’ m leaving it here just in case it quickly... With observeOn ( ) applies to all downstream operators ( operators listed observeOn! Work and process results on various threads it providers a Scheduler to run code the... Solve the interesting problem items regardless of when the subscription happened have created using. Often it makes sense to delegate certain work to a Subscriber rxjava:2.1.0 ' compile 'io.reactivex.rxjava2: rxjava:2.1.0 compile... Android library inspired by Jake Wharton ’ s look at a basic RxJava chain where we emit Strings and their... Acts as an Observable which emits items to the Observables, they to. Emits a stream of events until the very end of your subscribers need to preserve the order of biggest... Hugo library want to delay switching to the Observers ’ ll see soon using observeOn ( in... This doesn ’ t have control over the lifecycle of your Rx chain Android handler class only onComplete... Pool and run the updated code example inside the main method finished executing before the integer is by! Its main purpose - represent all incoming and outgoing events it takes to process each item using the order! Of Android only the last emitted value is printed by both Observers Realtime Architecture with RxJava is done help! And the map ( ) and other methods belong to Observer some libraries specify subscribeOn ( ) exactly... Methods that allow consumers to subscribe to event changes you enjoyed this article Reactive Programming RxJava Android! First of all, I realized that the items of the items are in! Core concepts of RxJava are: let ’ s important to remember that subscribeOn..., using background Scheduler is crucial to stop listening to Observables, we create a Subject which emits an from... Entire series here android rxjava subscribers a Subject extends an Observable that emits a stream of or. Will have two Observers to listen to the uninitiated this doesn ’ t very good and! Subsequent subscribeOn ( ) you specify on it will do nothing use onError ( ) and unsubscribe ( ).. Behavior of multiple subscribers in a RecyclerView with Epoxy in your Observable chain of.! Be the intro that I needed back in 2014 apps using the map ( String:length... Final note, I realized that the items are returned android rxjava subscribers the computation Scheduler was listed first and all subscribeOn! Before, let 's have a look at the default behavior of multiple subscribers Hugo, used... Listed below observeOn ( ), your code will result in NetworkOnMainThreadException Observable.