Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int threadCt = Runtime.getRuntime().availableProcessors() + 1;
ExecutorService executor = Executors.newFixedThreadPool(threadCt);
Schedulers scheduler = Schedulers.from(executor);
Observable.range(1,1000)
.groupBy(i -> batch.getAndIncrement() % threadCt )
.flatMap(g -> g.observeOn(scheduler)
.map(i -> intenseCalculation(i))
).subscribe(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment