|
org.codehaus.gpars | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovyx.gpars.GParsExecutorsPool
class GParsExecutorsPool
Enables a ExecutorService-based DSL on closures, objects and collections.
E.g.
GParsExecutorsPool.withPool(5) {ExecutorService service ->
Collection
Field Summary | |
---|---|
private static ThreadLocalPools |
currentPoolStack
Maps threads to their appropriate thread pools |
private static int |
defaultPoolSize
Caches the default pool size. |
Constructor Summary | |
GParsExecutorsPool()
|
Method Summary | |
---|---|
private static java.util.concurrent.ThreadFactory
|
createDefaultThreadFactory()
|
private static java.lang.Object
|
createPool()
Creates a new pool with the default size() |
private static java.lang.Object
|
createPool(int poolSize)
Creates a new pool with the given size() |
private static java.lang.Object
|
createPool(int poolSize, java.util.concurrent.ThreadFactory threadFactory)
|
static java.util.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 java.util.List
|
executeAsync(java.util.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 java.util.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 java.util.List
|
executeAsyncAndWait(java.util.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 java.util.concurrent.ExecutorService
|
retrieveCurrentPool()
Retrieves the pool assigned to the current thread. |
static void
|
shutdown()
|
static java.lang.Object
|
speculate(java.util.List alternatives)
Runs the supplied closures asynchronously and in parallel, returning the first result obtained and cancelling the other (slower) calculations. |
static java.lang.Object
|
speculate(groovy.lang.Closure... alternatives)
Runs the supplied closures asynchronously and in parallel, returning the first result obtained and cancelling the other (slower) calculations. |
static java.lang.Object
|
withExistingPool(java.util.concurrent.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 java.lang.Object
|
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 java.lang.Object
|
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 java.lang.Object
|
withPool(int numberOfThreads, java.util.concurrent.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 java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Field Detail |
---|
private static ThreadLocalPools currentPoolStack
private static final int defaultPoolSize
Constructor Detail |
---|
GParsExecutorsPool()
Method Detail |
---|
private static java.util.concurrent.ThreadFactory createDefaultThreadFactory()
private static java.lang.Object createPool()
private static java.lang.Object createPool(int poolSize)
private static java.lang.Object createPool(int poolSize, java.util.concurrent.ThreadFactory threadFactory)
static java.util.List executeAsync(groovy.lang.Closure... closures)
static java.util.List executeAsync(java.util.List closures)
static java.util.List executeAsyncAndWait(groovy.lang.Closure... closures)
static java.util.List executeAsyncAndWait(java.util.List closures)
protected static java.util.concurrent.ExecutorService retrieveCurrentPool()
static final void shutdown()
static java.lang.Object speculate(java.util.List alternatives)
alternatives
- All the functions to invoke in parallel
static java.lang.Object speculate(groovy.lang.Closure... alternatives)
alternatives
- All the functions to invoke in parallel
static java.lang.Object withExistingPool(java.util.concurrent.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 java.lang.Object 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 java.lang.Object 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 java.lang.Object withPool(int numberOfThreads, java.util.concurrent.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
Copyright © 2008–2013 Václav Pech. All Rights Reserved.