File tree Expand file tree Collapse file tree
src/main/java/com/baelding/rxjava Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5+ <modelVersion >4.0.0</modelVersion >
6+
7+ <groupId >com.baeldung</groupId >
8+ <artifactId >rxjava</artifactId >
9+ <version >1.0-SNAPSHOT</version >
10+ <build >
11+ <plugins >
12+ <plugin >
13+ <groupId >org.apache.maven.plugins</groupId >
14+ <artifactId >maven-compiler-plugin</artifactId >
15+ <configuration >
16+ <source >1.8</source >
17+ <target >1.8</target >
18+ </configuration >
19+ </plugin >
20+ </plugins >
21+ </build >
22+
23+ <dependencies >
24+ <dependency >
25+ <groupId >io.reactivex</groupId >
26+ <artifactId >rxjava</artifactId >
27+ <version >${rx.java.version} </version >
28+ </dependency >
29+ </dependencies >
30+
31+ <properties >
32+ <rx .java.version>1.2.5</rx .java.version>
33+ </properties >
34+
35+ </project >
Original file line number Diff line number Diff line change 1+ package com .baelding .rxjava ;
2+
3+
4+ import rx .schedulers .Schedulers ;
5+ import rx .subjects .PublishSubject ;
6+
7+ public class HotObservableBackPressure {
8+ public static void main (String [] args ) throws InterruptedException {
9+ PublishSubject <Integer > source = PublishSubject .create ();
10+
11+ source
12+ .observeOn (Schedulers .computation ())
13+ .subscribe (v -> compute (v ), Throwable ::printStackTrace );
14+
15+ for (int i = 0 ; i < 1_000_000 ; i ++) {
16+ source .onNext (i );
17+ }
18+
19+ Thread .sleep (10_000 );
20+ }
21+
22+ private static void compute (Integer v ) {
23+ try {
24+ System .out .println ("compute integer v: " + v );
25+ Thread .sleep (1000 );
26+ } catch (InterruptedException e ) {
27+ e .printStackTrace ();
28+ }
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments