Ive been reading a few docs for backpressure in RxJava, but i cant find a detailed explanation like how does it happen internally in the Library, everyone just summarize it like "producer" is too fast and "consumer" is too slow.
For example like the code below:
Observable.interval(1, TimeUnit.MILLISECONDS)
.observeOn(Schedulers.newThread())
.subscribe(
i -> {
System.out.println(i);
try {
Thread.sleep(100);
} catch (Exception e) { }
},
System.out::println);
Ive been going through the RxJava source code , so my understanding is that in main thread we are gonna emit events in every milliseconds and once we emit it we pass the value to the System.out.println(i) method and throw it into the newThead scheduler's thread pool and run the method inside a runnable.
So my question is , how does the exception happen internally? Cause when we call Thread.sleep(), we are just sleeping the thread that handles the method call -> System.out.println() without effecting other threads in the thread pool, how come it will cause an exception. Is it because the thread pool doesnt have enough available threads anymore?
Thanks