Search code examples
scalaparallel-collections

Will calling .seq on parallel collections ensure all threads are joined?


I have a collection on which I call .par, like this:

myCollection.par.map(element => longRunningOperation(element)).seq
println("after map")

Will calling .seq guarantee all threads are joined before continuing, and all maps completed, before calling println?


Solution

  • The worker threads are launched once the map operation is invoked. They are all joined by the framework before the map operation completes. By the time you call seq there are no more running worker threads.