org.apache.cocoon.thread.impl
Class DefaultThreadPool

java.lang.Object
  extended byEDU.oswego.cs.dl.util.concurrent.ThreadFactoryUser
      extended byEDU.oswego.cs.dl.util.concurrent.PooledExecutor
          extended byorg.apache.cocoon.thread.impl.DefaultThreadPool
All Implemented Interfaces:
EDU.oswego.cs.dl.util.concurrent.Executor, org.apache.cocoon.thread.ThreadPool

public class DefaultThreadPool
extends EDU.oswego.cs.dl.util.concurrent.PooledExecutor
implements org.apache.cocoon.thread.ThreadPool

The DefaultThreadPool class implements the ThreadPool interface. Instances of this class are made by the RunnableManager passing a threadpool into the init method.

   <!--+
       | More indepth information can be found at
       | http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/PooledExecutor.html
       | The following elements can be used:
       +-->
   <!-- required name of the pool -->
   <property name="name" value="default" />
   <!--+
       | optional priority all threads of the pool will have (the ThreadFactory will be
       | set to this priority).The possible values  are:
       |    MIN:  corresponds to Thread#MIN_PRIORITY
       |    NORM: corresponds to Thread#NORM_PRIORITY (default)
       |    MAX:  corresponds to Thread#MAX_PRIORITY
       +-->
   <property name="poolPriority" value="NORM" />
   <!--+
       | whether newly created Threads should run in daemon mode or not. Default to false.
       +-->
   <property name="daemon" value="false" />
   <!--+
       | optional size of a queue to hold Runnables if the pool is full. Possible values are:
      |    less than 0:    unbounded (default)
       |    equal to 0:     no queue at all
       |    greater than 0: size of the queue
    -->
   <property name="queueSize" value="-1" />
   <!--+
       | optional maximum number of threads in the pool. Defaults to 5.
       | NOTE: if a queue is specified (queue-sie != 0)
       |       this value will be ignored.
       +-->
   <property name="maxPoolSize" value="5" />
   <!--+
       | optional minimum number of threads in the pool. Defaults to 5.
       | NOTE: if a queue has been specified (queue-sie != 0)
       |       this value will be used as the maximum of thread running concurrently.
       +-->
   <property name="minPoolSize" value="5" />
   <!--+
       | The time in ms an idle thread should keep alive before it might get garbage collected.
       | This defaults to 60000 ms.
       +-->
   <property name="keepAliveTime" value="60000" />
   <!--+
       | The policy to be used if all resources (thread in the pool and
       | slots in the queue) are exhausted.
       | Possible values are:
       |    ABORT:         Throw a RuntimeException
       |    DISCARD:       Throw away the current request and return.
       |    DISCARDOLDEST: Throw away the oldest request and return.
       |    RUN (default): The thread making the execute request runs the task itself.
       |                   This policy helps guard against lockup.
       |    WAIT:          Wait until a thread becomes available. This policy should, in
       |                   general, not be used if the minimum number of threads is zero,
       |                   in which case a thread may never become available.
       +-->
   <property name="blockPolicy" value="ABORT" />
   <!--+
       | Terminate thread pool after processing all Runnables currently in queue. Any
       | Runnable entered after this point will be discarded. A shut down pool cannot
       | be restarted. This also means that a pool will need keep-alive-time-ms to
       | terminate. The default value not to shutdown graceful.
       +-->
   <property name="shutdownGraceful" value="false" />
   <!--+
       | The time in ms to wait before issuing an immediate shutdown after a graceful shutdown
       | has been requested.
       +-->
   <property name="shutdownWaitTimeMs" value="-1" />
   <!--+
       | specifies the fully qualified class name of an org.apache.cocoon.thread.ThreadFactory
       | implementation. It is responsible to create Thread classes.
       +-->
   <property name="factory" ref="defaultThreadFactory"/>
 

Version:
$Id: DefaultThreadPool.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Nested Class Summary
 
Nested classes inherited from class EDU.oswego.cs.dl.util.concurrent.PooledExecutor
EDU.oswego.cs.dl.util.concurrent.PooledExecutor.AbortWhenBlocked, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.BlockedExecutionHandler, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.DiscardOldestWhenBlocked, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.DiscardWhenBlocked, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.RunWhenBlocked, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.WaitWhenBlocked, EDU.oswego.cs.dl.util.concurrent.PooledExecutor.Worker
 
Nested classes inherited from class EDU.oswego.cs.dl.util.concurrent.ThreadFactoryUser
EDU.oswego.cs.dl.util.concurrent.ThreadFactoryUser.DefaultThreadFactory
 
Field Summary
protected  Log logger
          By default we use the logger for this class.
static String POLICY_DEFAULT
          Default ThreadPool block policy
 
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.PooledExecutor
blockedExecutionHandler_, DEFAULT_KEEPALIVETIME, DEFAULT_MAXIMUMPOOLSIZE, DEFAULT_MINIMUMPOOLSIZE, handOff_, keepAliveTime_, maximumPoolSize_, minimumPoolSize_, poolSize_, shutdown_, threads_
 
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.ThreadFactoryUser
threadFactory_
 
Fields inherited from interface org.apache.cocoon.thread.ThreadPool
DEFAULT_BLOCK_POLICY, DEFAULT_DAEMON_MODE, DEFAULT_KEEP_ALIVE_TIME, DEFAULT_MAX_POOL_SIZE, DEFAULT_MIN_POOL_SIZE, DEFAULT_QUEUE_SIZE, DEFAULT_SHUTDOWN_GRACEFUL, DEFAULT_SHUTDOWN_WAIT_TIME, DEFAULT_THREAD_PRIORITY, DEFAULT_THREADPOOL_NAME, POLICY_ABORT, POLICY_DISCARD, POLICY_DISCARD_OLDEST, POLICY_RUN, POLICY_WAIT, ROLE
 
Method Summary
 void execute(Runnable command)
          Execute a command
 String getBlockPolicy()
          Get the block policy
 org.apache.cocoon.thread.ThreadFactory getFactory()
           
 long getKeepAliveTime()
           
 int getMaxPoolSize()
           
 int getMaxQueueSize()
          DOCUMENT ME!
 int getMinPoolSize()
           
 String getName()
           
 int getPriority()
          Get hte priority used to create Threads
 int getQueueSize()
          DOCUMENT ME!
 int getShutdownWaitTimeMs()
          DOCUMENT ME!
 void init()
          Initialize the bean after properties set
 boolean isDaemon()
          Returns true if thread runs as daemon
 boolean isQueued()
          Whether this DefaultThreadPool has a queue
 boolean isShutdownGraceful()
          DOCUMENT ME!
 void setBlockPolicy(String blockPolicy)
          Set the blocking policy
 void setDaemon(boolean daemon)
          Set to true if thread shall run as daemon
 void setFactory(org.apache.cocoon.thread.ThreadFactory factory)
           
 void setKeepAliveTime(long keepAliveTime)
           
 void setMaxPoolSize(int maxPoolSize)
           
 void setMinPoolSize(int minPoolSize)
           
 void setName(String name)
          DOCUMENT ME!
 void setPoolPriority(String poolPriority)
           
 void setPriority(int priority)
           
 void setQueueSize(int queueSize)
          Sets the queue size of the thread pool
 void setShutdownGraceful(boolean shutdownGraceful)
          DOCUMENT ME!
 void setShutdownWaitTimeMs(int shutdownWaitTimeMs)
          DOCUMENT ME!
 void shutdown()
           
 String toString()
          Overwrite the toString method
 
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.PooledExecutor
abortWhenBlocked, addThread, awaitTerminationAfterShutdown, awaitTerminationAfterShutdown, createThreads, discardOldestWhenBlocked, discardWhenBlocked, drain, getBlockedExecutionHandler, getMaximumPoolSize, getMinimumPoolSize, getPoolSize, getTask, interruptAll, isTerminatedAfterShutdown, runWhenBlocked, setBlockedExecutionHandler, setMaximumPoolSize, setMinimumPoolSize, shutdownAfterProcessingCurrentlyQueuedTasks, shutdownAfterProcessingCurrentlyQueuedTasks, shutdownNow, shutdownNow, waitWhenBlocked, workerDone
 
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.ThreadFactoryUser
getThreadFactory, setThreadFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.thread.ThreadPool
isTerminatedAfterShutdown
 

Field Detail

POLICY_DEFAULT

public static final String POLICY_DEFAULT
Default ThreadPool block policy

See Also:
Constant Field Values

logger

protected final Log logger
By default we use the logger for this class.

Method Detail

init

public void init()
          throws IllegalArgumentException
Initialize the bean after properties set

Throws:
IllegalArgumentException

getBlockPolicy

public String getBlockPolicy()
Get the block policy

Specified by:
getBlockPolicy in interface org.apache.cocoon.thread.ThreadPool
Returns:
Returns the blockPolicy.

getMaxQueueSize

public int getMaxQueueSize()
DOCUMENT ME!

Specified by:
getMaxQueueSize in interface org.apache.cocoon.thread.ThreadPool
Returns:
maximum size of the queue (0 if isQueued() == false)
See Also:
ThreadPool.getQueueSize()

getName

public String getName()
Specified by:
getName in interface org.apache.cocoon.thread.ThreadPool
See Also:
ThreadPool.getName()

getPriority

public int getPriority()
Get hte priority used to create Threads

Specified by:
getPriority in interface org.apache.cocoon.thread.ThreadPool
Returns:
Thread.MIN_PRIORITY, Thread.NORM_PRIORITY, or Thread.MAX_PRIORITY

getQueueSize

public int getQueueSize()
DOCUMENT ME!

Specified by:
getQueueSize in interface org.apache.cocoon.thread.ThreadPool
Returns:
current size of the queue (0 if isQueued() == false)
See Also:
ThreadPool.getQueueSize()

isQueued

public boolean isQueued()
Whether this DefaultThreadPool has a queue

Specified by:
isQueued in interface org.apache.cocoon.thread.ThreadPool
Returns:
Returns the m_isQueued.
See Also:
ThreadPool.isQueued()

execute

public void execute(Runnable command)
             throws InterruptedException
Execute a command

Specified by:
execute in interface org.apache.cocoon.thread.ThreadPool
Parameters:
command - The Runnable to execute
Throws:
InterruptedException - In case of interruption

shutdown

public void shutdown()
See Also:
org.apache.cocoon.thread.ThreadPool#shutdown()

setBlockPolicy

public void setBlockPolicy(String blockPolicy)
Set the blocking policy

Parameters:
blockPolicy - The blocking policy value

setName

public void setName(String name)
DOCUMENT ME!

Parameters:
name - The name to set.

setShutdownGraceful

public void setShutdownGraceful(boolean shutdownGraceful)
DOCUMENT ME!

Parameters:
shutdownGraceful - The shutdownGraceful to set.

isShutdownGraceful

public boolean isShutdownGraceful()
DOCUMENT ME!

Specified by:
isShutdownGraceful in interface org.apache.cocoon.thread.ThreadPool
Returns:
Returns the shutdownGraceful.

setShutdownWaitTimeMs

public void setShutdownWaitTimeMs(int shutdownWaitTimeMs)
DOCUMENT ME!

Parameters:
shutdownWaitTimeMs - The shutdownWaitTimeMs to set.

getShutdownWaitTimeMs

public int getShutdownWaitTimeMs()
DOCUMENT ME!

Specified by:
getShutdownWaitTimeMs in interface org.apache.cocoon.thread.ThreadPool
Returns:
Returns the shutdownWaitTimeMs.

getKeepAliveTime

public long getKeepAliveTime()
Specified by:
getKeepAliveTime in interface org.apache.cocoon.thread.ThreadPool
Returns:
the keepAliveTime

setKeepAliveTime

public void setKeepAliveTime(long keepAliveTime)
Parameters:
keepAliveTime - the keepAliveTime to set

getMaxPoolSize

public int getMaxPoolSize()
Specified by:
getMaxPoolSize in interface org.apache.cocoon.thread.ThreadPool
Returns:
the maxPoolSize

setMaxPoolSize

public void setMaxPoolSize(int maxPoolSize)
Parameters:
maxPoolSize - the maxPoolSize to set

getMinPoolSize

public int getMinPoolSize()
Specified by:
getMinPoolSize in interface org.apache.cocoon.thread.ThreadPool
Returns:
the minPoolSize

setMinPoolSize

public void setMinPoolSize(int minPoolSize)
Parameters:
minPoolSize - the minPoolSize to set

getFactory

public org.apache.cocoon.thread.ThreadFactory getFactory()
Returns:
the threadFactory

setPriority

public void setPriority(int priority)
Parameters:
priority - the priority to set

setPoolPriority

public void setPoolPriority(String poolPriority)

setQueueSize

public void setQueueSize(int queueSize)
Sets the queue size of the thread pool

Parameters:
queueSize - the queueSize to set

isDaemon

public boolean isDaemon()
Returns true if thread runs as daemon

Specified by:
isDaemon in interface org.apache.cocoon.thread.ThreadPool
Returns:
the daemon

setDaemon

public void setDaemon(boolean daemon)
Set to true if thread shall run as daemon

Parameters:
daemon - the daemon to set

toString

public String toString()
Overwrite the toString method


setFactory

public void setFactory(org.apache.cocoon.thread.ThreadFactory factory)
Parameters:
factory - the factory to set


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.