_parallel
Def
Parallel
Parallel
Returns Stream.Flow with parallel execution
Each consecutive element will be sent to a new thread for processing
(1 <> 5).stream
.parallel
.map("Value: " + _ + "\t" + Thread.currentThread.getName)
.foreach(println)
// Possible Output
Value: 1 ForkJoinPool.commonPool-worker-9
Value: 3 ForkJoinPool.commonPool-worker-11
Value: 2 main
Value: 4 ForkJoinPool.commonPool-worker-2
Value: 5 ForkJoinPool.commonPool-worker-4
- Source
- _parallel.scala
Conditionally parallel
Conditionally parallel
Returns Stream.Flow with parallel or sequential implementation, depending on given parameter
(1 <> 50).stream.parallelIf(true).isParallel // Returns true
(1 <> 50).stream.parallelIf(false).isParallel // Returns false
- Source
- _parallel.scala
Conditionally parallel
Conditionally parallel
Returns Stream.Flow with parallel or sequential implementation, depending on stream having element count equal or greater than given ''threshold''
(1 <> 50).stream.parallelIfOver(100).isParallel // Returns false
(1 <> 200).stream.parallelIfOver(100).isParallel // Returns true
- Source
- _parallel.scala
Parallel with Priority
Parallel with Priority
This is very expensive operation, because it creates a custom thread pool. It only sutable for long running streams
(1 <> 100).stream.parallelWithPriority(MIN, 4).foreach(v => ())
(1 <> 100).stream.parallelWithPriority(MAX).foreach(v => ())
(1 <> 100).stream.parallelWithPriority(J.Priority(5), 4).foreach(v => ())
Note: parallelism
determines how many parallel threads are allowed. Default value is CPU core count minus 1
- Source
- _parallel.scala