I have a small program using List.par
val x = List(1,2,3,4,5).par.map(y => {
Thread.sleep(2000)
println(y)
y + 1
})
println(x)
Output:
3
1
4
5
2
ParVector(2, 3, 4, 5, 6)
The numbers are getting printed in parallel however the return value is always keeping its order.
My aim is to execute a sequence of insert statements to SQL database in parallel.
Currently I am using for comprehension. I want to use ParSeq as number of statements are increasing.
But I am afraid whether it results in performance degradation. (If there is extra code in map implementation for preserving its order, this is a performance overhead).
Kindly suggest me how to do it.