How to access and increase 'rx2.buffer-size' in RxJava 2?
Asked Answered
R

1

0

In http://reactivex.io/RxJava/javadoc/io/reactivex/Observable it is stated:

The Observable's operators, by default, run with a buffer size of 128 elements (see Flowable.bufferSize(), that can be overridden globally via the system parameter rx2.buffer-size.

My question is, how can I access and set rx2.buffer-size? If I do:

import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;
import io.reactivex.*;

...followed by:

Integer bufferSize = rx2.buffer-size;

I am informed by Studio that:

  • Unused import statement (for import io.reactivex.*;)
  • Cannot resolve symbol 'rx2'
  • Cannot resolve symbol 'size'

How can I override the system parameter rx2.buffer-size?

My project is using

io.reactivex.rxjava2/rxandroid/2.0.1
io.reactivex.rxjava2/rxjava/2.1.11
Ricky answered 23/10, 2018 at 19:33 Comment(0)
L
5

Try :

Integer bufferSize = Integer.parseInt(System.getProperty("rx2.buffer-size"))

To set a new value :

System.setProperty("rx2.buffer-size", 2048)
Lousewort answered 23/10, 2018 at 20:6 Comment(2)
Note that you have to do this before the RxJava classes are initialized.Hemisphere
@Lousewort Thanks! Integer bufferSize = Integer.parseInt(System.getProperty("rx2.buffer-size")) should be instead: Integer bufferSize = Integer.parseInt(System.getProperty("rx2.buffer-size", "42")) Where the 42 is a default value; otherwise a null will be returned (and Bad Things Happen) if the property is not already set. Also, 2048 needs to be a string, not an integer: System.setProperty("rx2.buffer-size", "2048")Ricky

© 2022 - 2024 — McMap. All rights reserved.