Unexplainable lack of performance improvement using RxJava Observables in Web Applications

后端 未结 1 1803
北荒
北荒 2021-02-07 14:36

I am performing some tests to evaluate if there is a real advantage in using reactive API\'s based on Observables, instead of the blocking traditional ones.

The whole ex

相关标签:
1条回答
  • 2021-02-07 15:01

    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.

    0 讨论(0)
提交回复
热议问题