groovyx.gpars.scheduler
Class DefaultPool

java.lang.Object
  extended by groovyx.gpars.scheduler.DefaultPool
All Implemented Interfaces:
Pool
Direct Known Subclasses:
ResizeablePool

public class DefaultPool
extends java.lang.Object
implements Pool

Represents the actors' thread pool, which performs tasks on behalf of the actors. The actors' thread pool size defaults to the n + 1, where n is the number of processors/cores available on the machine. The VM parameter -Dgpars.poolsize can be used the configure the default size of the actors' thread pool. The resize() and resetDefaultSize() methods can be used to configure size of the thread pool at runtime.

Author:
Vaclav Pech Date: Feb 27, 2009

Field Summary
private  java.util.concurrent.ThreadPoolExecutor pool
           
private static long SHUTDOWN_TIMEOUT
           
private static java.util.concurrent.atomic.AtomicLong threadCount
          Unique counter for Actors' threads
 
Fields inherited from interface groovyx.gpars.scheduler.Pool
POOL_SIZE_MUST_BE_A_POSITIVE_NUMBER, UNCAUGHT_EXCEPTION_OCCURRED_IN_ACTOR_POOL
 
Constructor Summary
DefaultPool()
          Creates the pool with default number of daemon threads.
DefaultPool(boolean daemon)
          Creates the pool with default number of threads.
DefaultPool(boolean daemon, int poolSize)
          Creates the pool with specified number of threads.
DefaultPool(java.util.concurrent.ThreadPoolExecutor pool)
          Creates the pool around the given executor service
 
Method Summary
private static java.util.concurrent.ThreadPoolExecutor createPool(boolean daemon, int poolSize)
          Creates a fixed-thread pool of given size.
protected static java.lang.String createThreadName()
          Created a JVM-unique name for Actors' threads.
 void execute(java.lang.Runnable task)
          schedules a new task for processing with the pool
 java.util.concurrent.ExecutorService getExecutorService()
          Retrieves the internal executor service.
 int getPoolSize()
          Retrieves the current thread pool size
 void resetDefaultSize()
          Sets the pool size to the default
 void resize(int poolSize)
          Resizes the thread pool to the specified value
 void shutdown()
          Gently stops the pool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

private final java.util.concurrent.ThreadPoolExecutor pool

SHUTDOWN_TIMEOUT

private static final long SHUTDOWN_TIMEOUT
See Also:
Constant Field Values

threadCount

private static final java.util.concurrent.atomic.AtomicLong threadCount
Unique counter for Actors' threads

Constructor Detail

DefaultPool

public DefaultPool()
Creates the pool with default number of daemon threads.


DefaultPool

public DefaultPool(boolean daemon)
Creates the pool with default number of threads.

Parameters:
daemon - Sets the daemon flag of threads in the pool.

DefaultPool

public DefaultPool(boolean daemon,
                   int poolSize)
Creates the pool with specified number of threads.

Parameters:
daemon - Sets the daemon flag of threads in the pool.
poolSize - The required size of the pool

DefaultPool

public DefaultPool(java.util.concurrent.ThreadPoolExecutor pool)
Creates the pool around the given executor service

Parameters:
pool - The executor service to use
Method Detail

createPool

private static java.util.concurrent.ThreadPoolExecutor createPool(boolean daemon,
                                                                  int poolSize)
Creates a fixed-thread pool of given size. Each thread will have the uncaught exception handler set to print the unhandled exception to standard error output.

Parameters:
daemon - Sets the daemon flag of threads in the pool.
poolSize - The required pool size @return The created thread pool
Returns:
The newly created thread pool

createThreadName

protected static java.lang.String createThreadName()
Created a JVM-unique name for Actors' threads.

Returns:
The name prefix

resize

public final void resize(int poolSize)
Resizes the thread pool to the specified value

Specified by:
resize in interface Pool
Parameters:
poolSize - The new pool size

resetDefaultSize

public final void resetDefaultSize()
Sets the pool size to the default

Specified by:
resetDefaultSize in interface Pool

getPoolSize

public int getPoolSize()
Retrieves the current thread pool size

Specified by:
getPoolSize in interface Pool
Returns:
The pool size

execute

public final void execute(java.lang.Runnable task)
schedules a new task for processing with the pool

Specified by:
execute in interface Pool
Parameters:
task - The task to schedule

getExecutorService

public final java.util.concurrent.ExecutorService getExecutorService()
Retrieves the internal executor service.

Returns:
The underlying thread pool

shutdown

public final void shutdown()
Gently stops the pool

Specified by:
shutdown in interface Pool

Copyright © 2008–2010 Václav Pech. All Rights Reserved.