Assume the following parallel process in Groovy/Gpars….
def result
GParsPool.withPool(5){
result = idList.collectParallel{processItem(it)}
}
If result is just an array list, and, assuming no thread accesses or manipulates result in processItem(), does result need to be explicitly synchronized? I need to know if I should be doing this instead…
def result = Collections.synchronizedList( new ArrayList())
GParsPool.withPool(5){
result = idList.collectParallel{processItem(it)}
}
I would be surprised if the result being returned is a
List, but if you look at this comment:here:
http://code.google.com/p/gparallelizer/source/browse/trunk/src/main/groovy/groovyx/gpars/Parallel.groovy?r=1138
it appears that when everything is done you can safely use the result, without having to have it synchronized.