org.apache.cocoon.components.thread
Class DefaultRunnableManager

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.thread.DefaultRunnableManager
All Implemented Interfaces:
Runnable, Disposable, Startable, Configurable, LogEnabled, ThreadSafe, RunnableManager

public class DefaultRunnableManager
extends AbstractLogEnabled
implements RunnableManager, Configurable, Disposable, Runnable, Startable, ThreadSafe

The DefaultRunnableManager implements the RunnableManager interface and is responsible to create ThreadPools and run Runnables in them as background commands.

The configuration of the DefaultRunnableManager:

   <thread-factory>org.apache.cocoon.components.thread.DefaultThreadFactory</thread-factory>
   <thread-pools>
     <thread-pool>
       <name>default</name>
       <priority>NORM</priority>
       <daemon>false</daemon>
       <queue-size>-1</queue-size>
       <max-pool-size>-1</max-pool-size>
       <min-pool-size>2</min-pool-size>
       <keep-alive-time-ms>20000</keep-alive-time-ms>
       <block-policy>RUN</block-policy>
       <shutdown-graceful>false</shutdown-graceful>
       <shutdown-wait-time-ms>-1</shutdown-wait-time-ms>
     </thread-pool>
   </thread-pools>
 

Have a look at http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/PooledExecutor.html, PooledExecutor or the cocoon.xconf file for more information.

Version:
$Id: DefaultRunnableManager.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Giacomo Pati

Field Summary
static boolean DEFAULT_DAEMON_MODE
          The default daemon mode
static long DEFAULT_KEEP_ALIVE_TIME
          The default keep alive time
static int DEFAULT_MAX_POOL_SIZE
          The default maximum pool size
static int DEFAULT_MIN_POOL_SIZE
          The default minimum pool size
static int DEFAULT_QUEUE_SIZE
          The default queue size
static boolean DEFAULT_SHUTDOWN_GRACEFUL
          The default way to shutdown gracefully
static int DEFAULT_SHUTDOWN_WAIT_TIME
          The default shutdown waittime time
static String DEFAULT_THREAD_FACTORY
          The default ThreadFactory
static String DEFAULT_THREAD_PRIORITY
          The default thread priority
static String DEFAULT_THREADPOOL_NAME
          The default shutdown waittime time
protected  SortedSet m_commandStack
          Sorted set of ExecutionInfo instances, based on their next execution time.
 
Fields inherited from interface org.apache.cocoon.components.thread.RunnableManager
ROLE
 
Constructor Summary
DefaultRunnableManager()
           
 
Method Summary
 void configure(Configuration config)
           
 ThreadPool createPool(int queueSize, int maxPoolSize, int minPoolSize, int priority, boolean isDaemon, long keepAliveTime, String blockPolicy, boolean shutdownGraceful, int shutdownWaitTime)
          Create a private ThreadPool
 void createPool(String name, int queueSize, int maxPoolSize, int minPoolSize, int priority, boolean isDaemon, long keepAliveTime, String blockPolicy, boolean shutdownGraceful, int shutdownWaitTime)
          Create a shared ThreadPool
 void dispose()
           
 void execute(Runnable command)
          Run a Runnable in the background using a ThreadPool
 void execute(Runnable command, long delay)
          Run a Runnable in the background using a ThreadPool
 void execute(Runnable command, long delay, long interval)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command, long delay)
          Run a Runnable in the background using a ThreadPool
 void execute(String threadPoolName, Runnable command, long delay, long interval)
          Run a Runnable in the background using a ThreadPool
 void remove(Runnable command)
          Remove a Runnable from the command stack
 void run()
          The heart of the command manager
 void start()
          Start the managing thread
 void stop()
          Stop the managing thread
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_THREAD_FACTORY

public static final String DEFAULT_THREAD_FACTORY
The default ThreadFactory


DEFAULT_QUEUE_SIZE

public static final int DEFAULT_QUEUE_SIZE
The default queue size

See Also:
Constant Field Values

DEFAULT_MAX_POOL_SIZE

public static final int DEFAULT_MAX_POOL_SIZE
The default maximum pool size

See Also:
Constant Field Values

DEFAULT_MIN_POOL_SIZE

public static final int DEFAULT_MIN_POOL_SIZE
The default minimum pool size

See Also:
Constant Field Values

DEFAULT_THREAD_PRIORITY

public static final String DEFAULT_THREAD_PRIORITY
The default thread priority

See Also:
Constant Field Values

DEFAULT_DAEMON_MODE

public static final boolean DEFAULT_DAEMON_MODE
The default daemon mode

See Also:
Constant Field Values

DEFAULT_KEEP_ALIVE_TIME

public static final long DEFAULT_KEEP_ALIVE_TIME
The default keep alive time

See Also:
Constant Field Values

DEFAULT_SHUTDOWN_GRACEFUL

public static final boolean DEFAULT_SHUTDOWN_GRACEFUL
The default way to shutdown gracefully

See Also:
Constant Field Values

DEFAULT_SHUTDOWN_WAIT_TIME

public static final int DEFAULT_SHUTDOWN_WAIT_TIME
The default shutdown waittime time

See Also:
Constant Field Values

DEFAULT_THREADPOOL_NAME

public static final String DEFAULT_THREADPOOL_NAME
The default shutdown waittime time

See Also:
Constant Field Values

m_commandStack

protected SortedSet m_commandStack
Sorted set of ExecutionInfo instances, based on their next execution time.

Constructor Detail

DefaultRunnableManager

public DefaultRunnableManager()
Method Detail

configure

public void configure(Configuration config)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

createPool

public void createPool(String name,
                       int queueSize,
                       int maxPoolSize,
                       int minPoolSize,
                       int priority,
                       boolean isDaemon,
                       long keepAliveTime,
                       String blockPolicy,
                       boolean shutdownGraceful,
                       int shutdownWaitTime)
Create a shared ThreadPool

Specified by:
createPool in interface RunnableManager
Parameters:
name - The name of the thread pool
queueSize - The size of the queue
maxPoolSize - The maximum number of threads
minPoolSize - The maximum number of threads
priority - The priority of threads created by this pool. This is one of Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, or Thread.MAX_PRIORITY
isDaemon - Whether or not thread from the pool should run in daemon mode
keepAliveTime - How long should a thread be alive for new work to be done before it is GCed
blockPolicy - What's the blocking policy is resources are exhausted
shutdownGraceful - Should we wait for the queue to finish all pending commands?
shutdownWaitTime - After what time a normal shutdown should take into account if a graceful shutdown has not come to an end
Throws:
IllegalArgumentException - If the pool already exists

createPool

public ThreadPool createPool(int queueSize,
                             int maxPoolSize,
                             int minPoolSize,
                             int priority,
                             boolean isDaemon,
                             long keepAliveTime,
                             String blockPolicy,
                             boolean shutdownGraceful,
                             int shutdownWaitTime)
Create a private ThreadPool

Specified by:
createPool in interface RunnableManager
Parameters:
queueSize - The size of the queue
maxPoolSize - The maximum number of threads
minPoolSize - The maximum number of threads
priority - The priority of threads created by this pool. This is one of Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, or Thread.MAX_PRIORITY
isDaemon - Whether or not thread from the pool should run in daemon mode
keepAliveTime - How long should a thread be alive for new work to be done before it is GCed
blockPolicy - What's the blocking policy is resources are exhausted
shutdownGraceful - Should we wait for the queue to finish all pending commands?
shutdownWaitTime - After what time a normal shutdown should take into account if a graceful shutdown has not come to an end
Returns:
A newly created ThreadPool

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

execute

public void execute(String threadPoolName,
                    Runnable command,
                    long delay,
                    long interval)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute
delay - the delay befor first run
interval - The interval for repeated runs
Throws:
IllegalArgumentException - DOCUMENT ME!

execute

public void execute(Runnable command,
                    long delay,
                    long interval)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
command - The Runnable to execute
delay - the delay befor first run
interval - The interval for repeated runs

execute

public void execute(Runnable command,
                    long delay)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
command - The Runnable to execute
delay - the delay befor first run

execute

public void execute(Runnable command)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
command - The Runnable to execute

execute

public void execute(String threadPoolName,
                    Runnable command,
                    long delay)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute
delay - the delay befor first run

execute

public void execute(String threadPoolName,
                    Runnable command)
Run a Runnable in the background using a ThreadPool

Specified by:
execute in interface RunnableManager
Parameters:
threadPoolName - The thread pool name to be used
command - The Runnable to execute

remove

public void remove(Runnable command)
Remove a Runnable from the command stack

Specified by:
remove in interface RunnableManager
Parameters:
command - The Runnable to be removed

run

public void run()
The heart of the command manager

Specified by:
run in interface Runnable

start

public void start()
           throws Exception
Start the managing thread

Specified by:
start in interface Startable
Throws:
Exception - DOCUMENT ME!

stop

public void stop()
          throws Exception
Stop the managing thread

Specified by:
stop in interface Startable
Throws:
Exception - DOCUMENT ME!


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.