def doInParallel(Closure... closures) {
def service = java.util.concurrent.Executors.newFixedThreadPool(closures.length)
def latch = new java.util.concurrent.CountDownLatch(closures.length)
closures.each { cl -> service.execute({
try {
cl.call()
} catch (e) {
throw e
} finally {
latch.countDown()
}
})}
latch.await()
service.shutdown()
}