Currently using rxjava ver 1.2.4 and rxandroid 1.2.1. I've a question regarding on .subscribeOn(Schedulers.io()) which i read from the javadoc which is:
"The implementation is backed by an Executor thread-pool that will grow as needed."
As see from the log I realize the number of threads keep increasing everytime I do some task:
12-28 11:17:03.879 D/HistoryDatabaseHelper: RxIoScheduler-22
12-28 11:17:03.918 D/HistoryDatabaseHelper: RxIoScheduler-19
12-28 11:17:03.918 D/HistoryDatabaseHelper: RxIoScheduler-18
RxIoScheduler-1, no?RxIoScheduler-1 is cleared when it's done its job? I'm worry soon the app will get OOM or somehow hit OOM when performing some heavy task because of the number of opening threads.
The io() Scheduler hosts a pool of single-threaded ScheduledExecutorServices which are handed out as workers when you use observeOn, subscribeOn and other operators that take a Scheduler. Until the associated sequence terminates or gets unsubscribed, that thread backing the worker is alive.
If you have multiple active sequences you get multiple IO Scheduler threads. Once done, they get back into the pool ready to be reused by another sequence. However, there is also a default 1 minute timeout that stops the threads if they don't get reused. If an operator then requires a worker again from the IO Scheduler, a new thread is started which gets a new value in its name, so you may get 19, 2002, etc. if the application runs long enough.
You may get OOM if your sequences don't terminate and just keep piling up, eventually running out of operating system threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With