2016-07-05 14:46:09 -06:00
|
|
|
// threads/ParallelStreamPuzzle3.java
|
|
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.*;
|
|
|
|
|
|
|
|
public class ParallelStreamPuzzle3 {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
List<Integer> x = IntStream.range(0, 30)
|
|
|
|
.peek(e -> System.out.println(e + ": " +
|
|
|
|
Thread.currentThread().getName()))
|
|
|
|
.limit(10)
|
|
|
|
.parallel()
|
|
|
|
.boxed()
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
System.out.println(x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Output:
|
2016-07-27 11:12:11 -06:00
|
|
|
8: main
|
2016-07-22 14:45:35 -06:00
|
|
|
6: ForkJoinPool.commonPool-worker-5
|
|
|
|
3: ForkJoinPool.commonPool-worker-7
|
2016-07-27 11:12:11 -06:00
|
|
|
5: ForkJoinPool.commonPool-worker-5
|
|
|
|
1: ForkJoinPool.commonPool-worker-3
|
2016-07-05 14:46:09 -06:00
|
|
|
2: ForkJoinPool.commonPool-worker-6
|
|
|
|
4: ForkJoinPool.commonPool-worker-1
|
2016-07-27 11:12:11 -06:00
|
|
|
0: ForkJoinPool.commonPool-worker-4
|
|
|
|
7: main
|
2016-07-05 14:46:09 -06:00
|
|
|
9: ForkJoinPool.commonPool-worker-2
|
|
|
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
|
|
|
*/
|