February 2019
Intermediate to advanced
442 pages
11h 46m
English
Hot Observable, on the other hand, has the producer created or activated outside of it. Hot Observable emits the stream that is shared by all observers. Let's see the example, as follows:
public class RxJavaHotObservable1 { public static void main(String args[]) { Observable<Long> observableInterval = Observable.interval(2, TimeUnit.SECONDS); PublishSubject<Long> publishSubject = PublishSubject.create(); observableInterval.subscribe(publishSubject); publishSubject.subscribe(i -> System.out.println("Observable #1 : "+i)); addDelay(4000); publishSubject.subscribe(i -> System.out.println("Observable #2 : "+i)); addDelay(10000); } private static void addDelay(int miliseconds) { try { Thread.sleep(miliseconds); } catch (InterruptedException ...