Java Parallel Streams API
Parallel Streams – How does it work?
class Test { public static void main(String[] args) { System.out.println(Runtime.getRuntime().availableProcessors()); } } IntStream.rangeClosed(1, 100000) .parallel() .sum();
Read More Parallel Streams – How does it work?Parallel Streams Performance Testing
private static void sumWithRegularStream() { for (int i = 0; i < 10; i++) { IntStream.rangeClosed(1, 100000).sum(); } } private static void sumWithParallelStream() { for (int i = 0; i < 10; i++) { IntStream.rangeClosed(1, 100000).parallel().sum(); } } class Test { public static void main(String[] args) { long regularStreamStartTime = System.currentTimeMillis(); sumWithRegularStream(); System.out.println(“Regular Stream execution…
Read More Parallel Streams Performance TestingIntroduction to Parallel Streams API in Java
class Test { public static void main(String[] args) { System.out.println(“Normal Stream…”); IntStream integers = IntStream.rangeClosed(1, 10); integers.forEach(num -> System.out.print(num + ” “)); System.out.println(); System.out.println(“Parallel Stream…”); IntStream integers2 = IntStream.rangeClosed(1, 10); integers2.parallel().forEach(num -> System.out.print(num + ” “)); } } Output: Normal Stream… 1 2 3 4 5 6 7 8 9 10 Parallel Stream… 7 6…
Read More Introduction to Parallel Streams API in Java