7

When I run the following code in the console (groovy 2.1.3):

strings =  [ "butter", "bread", "dragon", "table" ]
strings.eachParallel{println "$it0"}

I get:

groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.eachParallel() is applicable for argument types: (ConsoleScript40$_run_closure1) values: [ConsoleScript40$_run_closure1@a826f5]

Anyone can tell me what I am doing wrong?

Armin
  • 1,367
  • 1
  • 12
  • 17

1 Answers1

11

I think you are missing the set up. Try

@Grab(group='org.codehaus.gpars', module='gpars', version='1.0.0')
import groovyx.gpars.GParsPool

GParsPool.withPool {
    def strings =  [ "butter", "bread", "dragon", "table" ]
    strings.eachParallel { println it }
}
dmahapatro
  • 49,365
  • 7
  • 88
  • 117
Michael Rutherfurd
  • 13,815
  • 5
  • 29
  • 40
  • Thanks for that Michael. You did put me on the right track even-though I was unable to run the Grab as I am behind a proxy. Looking at your answer, I managed find out that the gpars dependency in grooyy-all's pom.xml is set to optional=true. And this causes the gpar dependency not to be included by default. So adding the gpar dependency explicitly to my pom fixed that issue for me. – Armin Jun 05 '13 at 05:00