Skip to content

Instantly share code, notes, and snippets.

@nithril
Last active August 29, 2015 14:06
Show Gist options
  • Save nithril/e8a263977b0def1701a6 to your computer and use it in GitHub Desktop.
Save nithril/e8a263977b0def1701a6 to your computer and use it in GitHub Desktop.
RxJava hanging
import org.junit.Test;
import rx.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.List;
/**
* Created by nithril on 06/04/14.
*/
public class RxJavaTest {
@Test
public void test1() throws InterruptedException {
List<Integer> list = new ArrayList<>();
for (int i = 0 ; i < 10_000_000 ; i++){
list.add(i);
}
rx.Observable.from(list).observeOn(Schedulers.computation()).parallel(obs -> obs.map(
val -> {
System.out.println(Thread.currentThread().getName() + " " + val);
return val;
})).subscribe();
while(true){
}
}
@Test
public void test2() throws InterruptedException {
List<Integer> list = new ArrayList<>();
for (int i = 0 ; i < 10_000_000 ; i++){
list.add(i);
}
rx.Observable.from(list).parallel(obs -> obs.map(
val -> {
System.out.println(Thread.currentThread().getName() + " " + val);
return val;
})).subscribe();
while(true){
}
}
@Test
public void test3() throws InterruptedException {
List<Integer> list = new ArrayList<>();
for (int i = 0 ; i < 10_000_000 ; i++){
list.add(i);
}
rx.Observable.from(list).parallel(obs -> obs).subscribe(v -> System.out.println(v));
while(true){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment