'How to Dispose an RxJava Scheduler.Worker (Scheduler.io) thread in SpringBoot application
Using RxJava I am running an API call asynchronously using Schedulers.io in a SpringBoot application:
Observable.fromCallable(() -> *API call code* )
.subscribeOn(Schedulers.io())
After that I suscribe to the Observable to get the answer:
Observable.subscribe(onSuccess(), onError());
According to the documentation, Schedulres.io might generate a unbounded number of Threads, so the Worker thread should be disposed with Schedulers.Worker.dispose() when the Thread work is finished.
However, I don't know how to get the Worker thread. Schedulers.createWorker seems to always create a new Worker thread on my application, instead of retrieving the current Worker thread.
Any ideas on how to dispose the Worker Thread for the API call thread?
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|