Unexplainable lack of performance improvement using RxJava Observables in Web Applications

拥有回忆 提交于 2019-12-03 10:38:05

The problem was caused by a programming error at some point. Actually the example in the question works perfectly.

One warning to prevent others from having problems: beware of using Observable.just(func), func is actually called on Observable creation. So any Thread.sleep placed there will block the calling thread

@Override
public Observable<List<Data>> loadDataObservable() {
    return Observable.just(generateData()).delay(500, TimeUnit.MILLISECONDS);
}

private List<Data> generateData(){
    List<Data> dataList = new ArrayList<Data>();
    for (int i = 0; i < 20; i++) {
        Data data = new Data("key"+i, "value"+i);
        dataList.add(data);
    }
    return dataList;
}

I started a discussion in RxJava Google group where they helped me work it out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!