I'm fiddling around with RxJava and Schedulers. I implemented a very simple stream with a scheduler:
Observable.just(1, 2, 3)
.doOnNext(v -> Thread.currentThread().getName())
.subscribeOn(Schedulers.newThread())
.subscribe(v -> System.out.println(v));
The example above prints nothing in the console.
I noticed, that when I block the main thread at the end using i.e. Thread.sleep(), System.out.println prints proper values - 1 2 3:
Observable.just(1, 2, 3)
.doOnNext(v -> Thread.currentThread().getName())
.subscribeOn(Schedulers.newThread())
.subscribe(v -> System.out.println(v));
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
Can someone help me understand this behaviour?