我刚接触RxJava,正在为一个(我猜)简单的问题而苦恼。我想要在三个线程中同时处理subscribe部分。因此我使用了FixedThreadPool。以下是示例代码:
Observer.just("one", "two", "three", "four")
.observeOn(Schedulers.io())
.subscribeOn(Schedulers.from(Executors.newFixedThreadPool(3))
.subscribe(new Observer<String>() {
public void onNext(String string) {
Log.d(TAG, "Started: " + string);
SystemClock.sleep(1000);
Log.d(TAG, "Ended: " + string);
}
(...)
}
期望结果:
Started: one
Started: two
Started: three
Ended: one
Started: four
Ended: two
Ended: three
Ended: four
实际结果:
Started: one
Ended: one
Started: two
Ended: two
Started: three
Ended: three
Started: four
Ended: four
我做错了什么?