|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgpars.GParsExecutorsPool
class GParsExecutorsPool
Enables a ExecutorService-based DSL on closures, objects and collections.
E.g.
GParsExecutorsPool.withPool(5) {ExecutorService service ->
Collection
Method Summary | |
---|---|
static List
|
executeAsync(groovy.lang.Closure... closures)
Starts multiple closures in separate threads, collecting Futures for their return values If an exception is thrown from the closure when called on any of the collection's elements, it will be re-thrown in the calling thread when it calls the Future.get() method. |
static List
|
executeAsync(List closures)
Starts multiple closures in separate threads, collecting Futures for their return values If an exception is thrown from the closure when called on any of the collection's elements, it will be re-thrown in the calling thread when it calls the Future.get() method. |
static List
|
executeAsyncAndWait(groovy.lang.Closure... closures)
Starts multiple closures in separate threads, collecting their return values If an exception is thrown from the closure when called on any of the collection's elements, it will be re-thrown in the calling thread when it calls the Future.get() method. |
static List
|
executeAsyncAndWait(List closures)
Starts multiple closures in separate threads, collecting their return values If an exception is thrown from the closure when called on any of the collection's elements, it will be re-thrown in the calling thread when it calls the Future.get() method. |
protected static ExecutorService
|
retrieveCurrentPool()
Retrieves the pool assigned to the current thread. |
static def
|
withExistingPool(ExecutorService pool, groovy.lang.Closure cl)
Creates a new instance of ExecutorService, binds it to the current thread, enables the ExecutorService DSL and runs the supplied closure. |
static def
|
withPool(groovy.lang.Closure cl)
Creates a new instance of ExecutorService, binds it to the current thread, enables the ExecutorService DSL and runs the supplied closure. |
static def
|
withPool(int numberOfThreads, groovy.lang.Closure cl)
Creates a new instance of ExecutorService, binds it to the current thread, enables the ExecutorService DSL and runs the supplied closure. |
static def
|
withPool(int numberOfThreads, ThreadFactory threadFactory, groovy.lang.Closure cl)
Creates a new instance of ExecutorService, binds it to the current thread, enables the ExecutorService DSL and runs the supplied closure. |
Methods inherited from class Object | |
---|---|
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
Method Detail |
---|
static List executeAsync(groovy.lang.Closure... closures)
static List executeAsync(List closures)
static List executeAsyncAndWait(groovy.lang.Closure... closures)
static List executeAsyncAndWait(List closures)
protected static ExecutorService retrieveCurrentPool()
static def withExistingPool(ExecutorService pool, groovy.lang.Closure cl)
def result = new ConcurrentSkipListSet() GParsExecutorsPool.withPool(5) {ExecutorService service -> [1, 2, 3, 4, 5].eachParallel{Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
pool
- The ExecutorService to use, the service will not be shutdown after this method returns
static def withPool(groovy.lang.Closure cl)
def result = new ConcurrentSkipListSet() GParsExecutorsPool.withPool {ExecutorService service -> [1, 2, 3, 4, 5].eachParallel{Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
cl
- The block of code to invoke with the DSL enabled
static def withPool(int numberOfThreads, groovy.lang.Closure cl)
def result = new ConcurrentSkipListSet() GParsExecutorsPool.withPool(5) {ExecutorService service -> [1, 2, 3, 4, 5].eachParallel{Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
numberOfThreads
- Number of threads in the newly created thread poolcl
- The block of code to invoke with the DSL enabled
static def withPool(int numberOfThreads, ThreadFactory threadFactory, groovy.lang.Closure cl)
def result = new ConcurrentSkipListSet() GParsExecutorsPool.withPool(5) {ExecutorService service -> [1, 2, 3, 4, 5].eachParallel{Number number -> result.add(number * 10)}* assertEquals(new HashSet([10, 20, 30, 40, 50]), result) }*
numberOfThreads
- Number of threads in the newly created thread poolthreadFactory
- Factory for threads in the poolcl
- The block of code to invoke with the DSL enabled
Groovy Documentation