|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgpars.GParsPool
class GParsPool
Enables a ParallelArray-based (from JSR-166y) DSL on collections. In general cases the Parallel Array implementation shows to be much faster (10 - 20 times) compared to the executor service implementation in GParsExecutorsPool. E.g.
GParsPool.withPool(5) {final AtomicInteger result = new AtomicInteger(0) [1, 2, 3, 4, 5].eachParallel {result.addAndGet(it)}assertEquals 15, result}GParsPool.withPool(5) {final List result = [1, 2, 3, 4, 5].collectParallel {it * 2}assert ([2, 4, 6, 8, 10].equals(result))}GParsPool.withPool(5) {assert [1, 2, 3, 4, 5].everyParallel {it > 0}assert ![1, 2, 3, 4, 5].everyParallel {it > 1}}
Constructor Summary | |
GParsPool()
|
Method Summary | |
---|---|
static def
|
ensurePool(def pool, groovy.lang.Closure cl)
Just like withExistingPool() registers a thread pool, but doesn't install the GParsPoolUtil category. |
static List
|
executeAsync(groovy.lang.Closure closures)
Starts multiple closures in separate threads, collecting Futures for their return values Reuses the pool defined by the surrounding withPool() call. |
static List
|
executeAsync(List closures)
Starts multiple closures in separate threads, collecting Futures for their return values Reuses the pool defined by the surrounding withPool() call. |
static List
|
executeAsyncAndWait(groovy.lang.Closure closures)
Starts multiple closures in separate threads, collecting their return values Reuses the pool defined by the surrounding withPool() call. |
static List
|
executeAsyncAndWait(List closures)
Starts multiple closures in separate threads, collecting their return values Reuses the pool defined by the surrounding withPool() call. |
protected static def
|
retrieveCurrentPool()
Retrieves the pool assigned to the current thread. |
static T
|
runForkJoin(AbstractForkJoinWorker rootWorker)
Starts a ForkJoin calculation with the supplied root worker and waits for the result. |
static T
|
runForkJoin(Object args)
Starts a ForkJoin calculation with the supplied root worker and waits for the result. |
static def
|
withExistingPool(def pool, groovy.lang.Closure cl)
Reuses an instance of ForkJoinPool, binds it to the current thread, enables the ParallelArray DSL and runs the supplied closure. |
static def
|
withPool(groovy.lang.Closure cl)
Creates a new instance of ForkJoinPool, binds it to the current thread, enables the ParallelArray DSL and runs the supplied closure. |
static def
|
withPool(int numberOfThreads, groovy.lang.Closure cl)
Creates a new instance of ForkJoinPool, binds it to the current thread, enables the ParallelArray DSL and runs the supplied closure. |
static def
|
withPool(int numberOfThreads, UncaughtExceptionHandler handler, groovy.lang.Closure cl)
Creates a new instance of ForkJoinPool, binds it to the current thread, enables the ParallelArray DSL and runs the supplied closure. |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Constructor Detail |
---|
GParsPool()
Method Detail |
---|
public static def ensurePool(def pool, groovy.lang.Closure cl)
public static List executeAsync(groovy.lang.Closure closures)
public static List executeAsync(List closures)
public static List executeAsyncAndWait(groovy.lang.Closure closures)
public static List executeAsyncAndWait(List closures)
protected static def retrieveCurrentPool()
public static T runForkJoin(AbstractForkJoinWorker rootWorker)
public static T runForkJoin(Object args)
public static def withExistingPool(def pool, groovy.lang.Closure cl)
GParsPool.withExistingPool(anotherPool) {GParsPool pool -> def result = Collections.synchronizedSet(new HashSet()) [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
public static def withPool(groovy.lang.Closure cl)
GParsPool.withPool {GParsPool pool -> def result = Collections.synchronizedSet(new HashSet()) [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
public static def withPool(int numberOfThreads, groovy.lang.Closure cl)
GParsPool.withPool(5) {GParsPool pool -> def result = Collections.synchronizedSet(new HashSet()) [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
public static def withPool(int numberOfThreads, UncaughtExceptionHandler handler, groovy.lang.Closure cl)
GParsPool.withPool(5, handler) {GParsPool pool -> def result = Collections.synchronizedSet(new HashSet()) [1, 2, 3, 4, 5].eachParallel {Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
Groovy Documentation