org.norther.tammi.core.thread
Class DefaultPooledExecutor

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.core.thread.AbstractExecutor
          extended by org.norther.tammi.core.thread.DefaultThreadedExecutor
              extended by org.norther.tammi.core.thread.DefaultPooledExecutor
All Implemented Interfaces:
Serializable, Executor, ExecutorService, EventListener, NotificationBroadcaster, NotificationEmitter, NotificationListener, Manageable, MBeanDelegate, Startable, PooledExecutor, ThreadedExecutor

public class DefaultPooledExecutor
extends DefaultThreadedExecutor
implements PooledExecutor

A default implementation of PooledExecutor.

Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
static class DefaultPooledExecutor.AbortPolicy
          A handler for rejected tasks that aborts the rejected task.
static class DefaultPooledExecutor.CallerRunsPolicy
          A handler for rejected tasks that runs the rejected task directly in the calling thread of the execute method.
static class DefaultPooledExecutor.DiscardOldestPolicy
          A handler for rejected tasks that discards the oldest unhandled request and then retries execute.
static class DefaultPooledExecutor.DiscardPolicy
          A handler for rejected tasks that silently discards the rejected task.
static class DefaultPooledExecutor.QueuePolicy
          A handler for rejected tasks that queues the rejected task.
 
Field Summary
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Fields inherited from interface org.norther.tammi.core.base.MBeanDelegate
ARRAY_TYPE, OBJECT_TYPE, PRIMITIVE_TYPE, STRING_TYPE
 
Constructor Summary
DefaultPooledExecutor(int capacity)
          Constructs a new pooled executor.
 
Method Summary
 int getCorePoolSize()
          Gets the number of threads to cache (default = 0).
 long getKeepAliveTime()
          Gets the number of milliseconds to keep alive threads exceeding the number of core threads waiting for new commands.
 int getLargestPoolSize()
          Gets the largest number of active threads in the pool ever.
 int getMaxPoolSize()
          Gets the maximum number of threads to simultaneously execute.
 int getPoolSize()
          Gets the current number of active threads in the pool.
 int getQueueCapacity()
          Gets the queue capacity of the executor.
 RejectedExecutionHandler getRejectedExecutionHandler()
          Gets the rejected execution handler.
protected  ExecutorService newExecutor()
          Creates the implementation of the executor.
 int prestartAllCoreThreads()
          Creates and starts the core threads in the pool.
 boolean prestartCoreThread()
          Creates and starts a new core thread in the pool.
 void purge()
          Purges cancelled tasks from the queue.
 boolean remove(Runnable task)
          Removes the specified task.
 void setCorePoolSize(int size)
          Set the number of threads to cache.
 void setKeepAliveTime(long msecs)
          Sets the number of milliseconds to keep alive threads exceeding the number of core threads waiting for new commands.
 void setMaxPoolSize(int size)
          Sets the maximum number of threads to use.
 void setRejectedExecutionHandler(RejectedExecutionHandler handler)
          Sets the rejected execution handler.
 
Methods inherited from class org.norther.tammi.core.thread.DefaultThreadedExecutor
getExecutor, getThreadFactoryName, handleNotification, postmanaged, setThreadFactoryName, unmanaged
 
Methods inherited from class org.norther.tammi.core.thread.AbstractExecutor
awaitTermination, execute, getActiveCount, getCompletedTaskCount, getTaskCount, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isStarted, isTerminated, shutdown, shutdownNow, start, stop, submit, submit, submit
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, premanaged, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.core.thread.ThreadedExecutor
getThreadFactoryName, setThreadFactoryName
 
Methods inherited from interface org.norther.tammi.core.thread.Executor
getActiveCount, getCompletedTaskCount, getTaskCount
 
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
 
Methods inherited from interface java.util.concurrent.Executor
execute
 
Methods inherited from interface org.norther.tammi.core.base.Startable
isStarted, start, stop
 

Constructor Detail

DefaultPooledExecutor

public DefaultPooledExecutor(int capacity)
Constructs a new pooled executor.

Parameters:
capacity - the capacity of a command queue.
Method Detail

getQueueCapacity

public int getQueueCapacity()
Description copied from interface: PooledExecutor
Gets the queue capacity of the executor.

Specified by:
getQueueCapacity in interface PooledExecutor
Returns:
the queue capacity.

getKeepAliveTime

public long getKeepAliveTime()
Description copied from interface: PooledExecutor
Gets the number of milliseconds to keep alive threads exceeding the number of core threads waiting for new commands. A negative value means to wait forever. A zero value means not to wait at all.

Specified by:
getKeepAliveTime in interface PooledExecutor
Returns:
the keep alive time in msecs.

setKeepAliveTime

public void setKeepAliveTime(long msecs)
Description copied from interface: PooledExecutor
Sets the number of milliseconds to keep alive threads exceeding the number of core threads waiting for new commands. A negative value means to wait forever. A zero value means not to wait at all.

Specified by:
setKeepAliveTime in interface PooledExecutor
Parameters:
msecs - the keep alive time in msecs.

getMaxPoolSize

public int getMaxPoolSize()
Description copied from interface: PooledExecutor
Gets the maximum number of threads to simultaneously execute. New unqueued requests will be handled according to the current blocking policy once this limit is exceeded.

Specified by:
getMaxPoolSize in interface PooledExecutor
Returns:
the max pool size.

setMaxPoolSize

public void setMaxPoolSize(int size)
Description copied from interface: PooledExecutor
Sets the maximum number of threads to use. Decreasing the pool size will not immediately kill existing threads, but they may later die when idle.

Specified by:
setMaxPoolSize in interface PooledExecutor
Parameters:
size - the max pool size or -1 for unlimited.

getCorePoolSize

public int getCorePoolSize()
Description copied from interface: PooledExecutor
Gets the number of threads to cache (default = 0).

Specified by:
getCorePoolSize in interface PooledExecutor
Returns:
the core pool size.

setCorePoolSize

public void setCorePoolSize(int size)
Description copied from interface: PooledExecutor
Set the number of threads to cache.

Specified by:
setCorePoolSize in interface PooledExecutor
Parameters:
size - the core pool size.

getPoolSize

public int getPoolSize()
Description copied from interface: PooledExecutor
Gets the current number of active threads in the pool. This number is just a snaphot, and may change immediately upon returning.

Specified by:
getPoolSize in interface PooledExecutor
Returns:
the current pool size.

getLargestPoolSize

public int getLargestPoolSize()
Description copied from interface: PooledExecutor
Gets the largest number of active threads in the pool ever.

Specified by:
getLargestPoolSize in interface PooledExecutor
Returns:
the largest pool size.

getRejectedExecutionHandler

public RejectedExecutionHandler getRejectedExecutionHandler()
Description copied from interface: PooledExecutor
Gets the rejected execution handler.

Specified by:
getRejectedExecutionHandler in interface PooledExecutor
Returns:
the handler to apply.

setRejectedExecutionHandler

public void setRejectedExecutionHandler(RejectedExecutionHandler handler)
Description copied from interface: PooledExecutor
Sets the rejected execution handler.

Specified by:
setRejectedExecutionHandler in interface PooledExecutor
Parameters:
handler - the handler to apply.

prestartCoreThread

public boolean prestartCoreThread()
Description copied from interface: PooledExecutor
Creates and starts a new core thread in the pool.

Specified by:
prestartCoreThread in interface PooledExecutor
Returns:
false if all already started, true otherwise.

prestartAllCoreThreads

public int prestartAllCoreThreads()
Description copied from interface: PooledExecutor
Creates and starts the core threads in the pool. Return the number created.

Specified by:
prestartAllCoreThreads in interface PooledExecutor
Returns:
the number of created threads.

purge

public void purge()
Description copied from interface: PooledExecutor
Purges cancelled tasks from the queue.

Specified by:
purge in interface PooledExecutor

remove

public boolean remove(Runnable task)
Description copied from interface: PooledExecutor
Removes the specified task.

Specified by:
remove in interface PooledExecutor
Parameters:
task - the task.
Returns:
true if successful, false otherwise.

newExecutor

protected ExecutorService newExecutor()
Description copied from class: AbstractExecutor
Creates the implementation of the executor.

Overrides:
newExecutor in class DefaultThreadedExecutor
Returns:
the executor implementation.


Copyright © 2004 The Norther Organization. All rights reserved.