Rxjava in scheduler IO () does not work in the thread
•
Java
The problem is: I have observable and subscriber I'm trying Start observable in the IO () thread because it applies to files and zip archives (I won't show the code – too large), but observable does nothing!:
Observable<Double> creatingObservable = getCreatingObservable(image); Subscriber<Double> creatingSubscriber = getCreatingSubscriber(); creatingObservable .subscribeOn(Schedulers.io()) .subscribe(creatingSubscriber);
If I start the code without subscribeon () – all work What is the problem and how to solve it
Attachment: system out. Println () doesn't work either The problem has all the threads of the scheduler
Solution
The problem seems to be that the main thread terminated before createobservable can emit any value
Simple solution: make the main thread wait long enough for creationobservable to issue / complete
Observable<Double> creatingObservable = getCreatingObservable(image); Subscriber<Double> creatingSubscriber = getCreatingSubscriber(); creatingObservable .subscribeOn(Schedulers.io()) .subscribe(creatingSubscriber); Thread.sleep(5000); //to wait 5 seconds while creatingObservable is running on IO thread
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码