BEAL-572 onBackpressure operations
This commit is contained in:
parent
2065c3ca51
commit
51d8c0cdb7
|
@ -34,4 +34,12 @@ public class ComputeFunction {
|
|||
}
|
||||
|
||||
|
||||
public static void compute(Long v) {
|
||||
try {
|
||||
System.out.println("compute integer v: " + v);
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package com.baelding.rxjava;
|
||||
|
||||
|
||||
import rx.BackpressureOverflow;
|
||||
import rx.Observable;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class HotObservableOnBackPressure {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
Observable.range(1, 1_000_000)
|
||||
.onBackpressureBuffer(16, () -> {
|
||||
},
|
||||
BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(e -> {
|
||||
}, Throwable::printStackTrace);
|
||||
|
||||
|
||||
Observable.interval(1, TimeUnit.MINUTES)
|
||||
.onBackpressureDrop()
|
||||
// .onBackpressureLatest()
|
||||
.observeOn(Schedulers.io())
|
||||
.doOnNext(ComputeFunction::compute)
|
||||
.subscribe(v -> {
|
||||
}, Throwable::printStackTrace);
|
||||
Thread.sleep(10_000);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue