Observable.create(new Observable.OnSubscribe() { @Override public void call(Subscriber subscriber) { subscriber.onNext("-->robin"); subscriber.onCompleted(); Log.i("robin","0-->"+Thread.currentThread().getName()); } }) .map(new Func1() { @Override public String call(String s) { Log.i("robin","1-->"+Thread.currentThread().getName()); return s; } }) .subscribeOn(Schedulers.io()) .map(new Func1() { @Override public String call(String o) { Log.i("robin","2-->"+Thread.currentThread().getName()); return o; } }) .observeOn(AndroidSchedulers.mainThread()) .map(new Func1() { @Override public String call(String o) { Log.i("robin","3-->"+Thread.currentThread().getName()); return o; } }) .observeOn(Schedulers.io()) .map(new Func1() { @Override public String call(String o) { Log.i("robin","5-->"+Thread.currentThread().getName()); return o; } }) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(String o) { Log.i("robin","4-->"+Thread.currentThread().getName()+o); } });
结论
1、observeOn修改的是他 下面 的代码执行的线程
subscribeOn修改的是他 上面 执行代码的线程
2、observeOn之后在调用observeOn还可以修改线程,但是调用subscribeOn就不能再修改线程
subscribeOn之后在调用observeOn还可以修改线程,但是调用subscribeOn就不能再修改线程