jPOS 1.6.1 API Documentation

org.jpos.util
Class ThreadPool

java.lang.Object
  extended by java.lang.ThreadGroup
      extended by org.jpos.util.ThreadPool
All Implemented Interfaces:
java.lang.Thread.UncaughtExceptionHandler, Configurable, Loggeable, LogSource, ThreadPoolMBean

public class ThreadPool
extends java.lang.ThreadGroup
implements LogSource, Loggeable, Configurable, ThreadPoolMBean

Implements a ThreadPool with the ability to run simple Runnable tasks as well as Jobs (supervised Runnable tasks)

Since:
1.1
Author:
apr@cs.com.uy

Nested Class Summary
static interface ThreadPool.Supervised
           
 
Field Summary
static int DEFAULT_MAX_THREADS
           
 
Constructor Summary
ThreadPool()
          Default constructor for ThreadPool
ThreadPool(int poolSize, int maxPoolSize)
           
ThreadPool(int poolSize, int maxPoolSize, java.lang.String name)
           
 
Method Summary
 void close()
           
 void dump(java.io.PrintStream p, java.lang.String indent)
           
 void execute(java.lang.Runnable action)
           
 int getAvailableCount()
           
 int getIdleCount()
           
 int getJobCount()
           
 Logger getLogger()
           
 int getMaxPoolSize()
           
 int getPendingCount()
           
 int getPoolSize()
           
 java.lang.String getRealm()
           
static ThreadPool getThreadPool(java.lang.String name)
          Retrieves a thread pool from NameRegistrar given its name, unique identifier.
 void setConfiguration(Configuration cfg)
           
 void setLogger(Logger logger, java.lang.String realm)
           
 void supervise()
           
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MAX_THREADS

public static final int DEFAULT_MAX_THREADS
See Also:
Constant Field Values
Constructor Detail

ThreadPool

public ThreadPool(int poolSize,
                  int maxPoolSize)
Parameters:
poolSize - starting pool size
maxPoolSize - maximum number of threads on this pool

ThreadPool

public ThreadPool(int poolSize,
                  int maxPoolSize,
                  java.lang.String name)
Parameters:
name - pool name
poolSize - starting pool size
maxPoolSize - maximum number of threads on this pool

ThreadPool

public ThreadPool()
Default constructor for ThreadPool

Method Detail

close

public void close()

execute

public void execute(java.lang.Runnable action)
             throws BlockingQueue.Closed
Throws:
BlockingQueue.Closed

dump

public void dump(java.io.PrintStream p,
                 java.lang.String indent)
Specified by:
dump in interface Loggeable

getJobCount

public int getJobCount()
Specified by:
getJobCount in interface ThreadPoolMBean
Returns:
number of jobs processed by this pool

getPoolSize

public int getPoolSize()
Specified by:
getPoolSize in interface ThreadPoolMBean
Returns:
number of active threads

getMaxPoolSize

public int getMaxPoolSize()
Specified by:
getMaxPoolSize in interface ThreadPoolMBean
Returns:
max number of active threads allowed

getIdleCount

public int getIdleCount()
Specified by:
getIdleCount in interface ThreadPoolMBean
Returns:
number of idle threads

getAvailableCount

public int getAvailableCount()
Returns:
number of available threads

getPendingCount

public int getPendingCount()
Specified by:
getPendingCount in interface ThreadPoolMBean
Returns:
number of Pending jobs

supervise

public void supervise()

setLogger

public void setLogger(Logger logger,
                      java.lang.String realm)
Specified by:
setLogger in interface LogSource

getRealm

public java.lang.String getRealm()
Specified by:
getRealm in interface LogSource

getLogger

public Logger getLogger()
Specified by:
getLogger in interface LogSource

setConfiguration

public void setConfiguration(Configuration cfg)
                      throws ConfigurationException
Specified by:
setConfiguration in interface Configurable
Parameters:
cfg - Configuration object
Throws:
ConfigurationException

getThreadPool

public static ThreadPool getThreadPool(java.lang.String name)
                                throws NameRegistrar.NotFoundException
Retrieves a thread pool from NameRegistrar given its name, unique identifier.

Parameters:
name - Name of the thread pool to retrieve, must be the same as the name property of the thread-pool tag in the QSP config file
Returns:
returns the retrieved instance of thread pool
Throws:
NameRegistrar.NotFoundException - thrown when there is not a thread-pool registered under this name.

jPOS.org