Class QThreadPoolExecutor
java.lang.Object
org.jpos.q2.QBeanSupport
org.jpos.q2.qbean.QThreadPoolExecutor
- All Implemented Interfaces:
Configurable, QBean, QThreadPoolExecutorMBean, QBeanSupportMBean, QPersist
A qbean dedicated to thread pool executor creation and registration by Q2
NameRegistrar registry
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefaultXML_CONFIG_ATTR__EXEC_SRV_TERMINATION_TIMERvalue, in seconds.static final StringPrefix used when registering pooled executors inNameRegistrar.static final StringXML attribute setting the executor's core pool size.static final StringXML attribute setting the awaitTermination timeout, in seconds.static final StringXML attribute selecting the executor type (fixed,cached,scheduled,single).Fields inherited from class QBeanSupport
cfg, log, scheduledThreadPoolExecutorModifier and TypeFieldDescriptionprotected ConfigurationConfiguration applied to this bean by the container.protected LogLogger associated with this bean.protected ScheduledThreadPoolExecutorLazily-allocated scheduler shared with subclasses; seeQBeanSupport.getScheduledThreadPoolExecutor().Fields inherited from interface QBean
DESTROYED, FAILED, STARTED, STARTING, stateString, STOPPED, STOPPINGModifier and TypeFieldDescriptionstatic final intQBean has been destroyed.static final intQBean has failed.static final intQBean is running.static final intQBean is in the process of starting.static final String[]Human-readable names for each QBean state, indexed by state constant.static final intQBean is stopped.static final intQBean is in the process of stopping. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the approximate number of threads that are actively executing tasks.protected org.jdom2.AttributegetAttribute(org.jdom2.Element elt, String attrName, boolean mandatory, String errDesc) Returns a required or optional XML attribute, raising a configuration error witherrDescas context when a mandatory attribute is missing or empty.longReturns the approximate total number of tasks that have completed execution.intReturns the core number of threads.Returns the executor service type.intReturns the core pool size requested at configuration time.longReturns the thread keep-alive time in milliseconds.intReturns the largest number of threads that have ever simultaneously been in the pool.intReturns the maximum allowed number of threads.intReturns the current number of threads in the pool.protected StringReturns theNameRegistrarkey under which this bean's executor is registered.longReturns the approximate total number of tasks that have been scheduled for execution.intReturns the await-termination delay in milliseconds.static ThreadPoolExecutorgetThreadPoolExecutor(String name) Retrieves a thread pool executor from NameRegistrar given its name.static <T extends ThreadPoolExecutor>
TgetThreadPoolExecutor(String name, Class<T> clazz) Retrieves a thread pool executor from NameRegistrar given its name and expected class.protected voidHandle specific config elements type := "fixed" | "scheduled" | "cached" corePoolSize := integer (required for "fixed" and "scheduled" kinds, optional for "cached" kind)booleanReturns whether this executor has been shut down.booleanReturns whether all tasks have completed following shut down.booleanReturns whether this executor is in the process of terminating after shutdown.protected voidsetExecSrvType(String execSrvType) Sets the executor type (fixed,cached,scheduled, orsingle).protected voidsetInitialCorePoolSize(int initialCorePoolSize) Sets the initial core pool size used when the executor is created.protected voidsetTerminationTimer(int terminationTimer) Sets the awaitTermination timeout, in seconds.protected voidCalled during the start lifecycle phase; subclasses may override.protected voidCalled during the stop lifecycle phase; subclasses may override.Methods inherited from class QBeanSupport
addAttr, close, createElement, defaultRealm, destroy, destroyService, getAttrs, getAttrs, getConfiguration, getDump, getFactory, getLoader, getLoaderURLS, getLog, getLogger, getName, getPersist, getProperties, getProperty, getRealm, getScheduledThreadPoolExecutor, getServer, getState, getStateAsString, init, isModified, running, setAttr, setConfiguration, setLogger, setModified, setName, setPersist, setProperty, setRealm, setServer, setState, start, stopModifier and TypeMethodDescriptionprotected voidAppends an<attr>child element with name/type/value toe.protected voidCloses a sequence ofCloseableresources, logging any failures as a warning.protected org.jdom2.ElementcreateElement(String name, Class mbeanClass) Builds a JDOMElementreflecting the bean's persistent attributes, driven by the JavaBean introspection ofmbeanClass.protected StringReturns the default realm for this bean; subclasses may override.voiddestroy()destroy the serviceprotected voidCalled during the destroy lifecycle phase; subclasses may override.protected IteratorgetAttrs()Iterates over top-level<attr>children of the persisted element.protected IteratorIterates over<attr>children nested under the given parent element name.Returns the configuration applied to this bean.getDump()Returns a textual dump of this bean's state.Returns theQFactoryassociated with the hosting Q2 server.Returns the QClassLoader for this bean.URL[]Returns the URLs registered with the class loader.getLog()Returns theLogused by this bean.Returns the logger name.getName()Returns the bean name.org.jdom2.ElementReturns the persistent configuration element for this QBean.protected IteratorgetProperties(String parent) Iterates over<property>children nested under the given parent element name.protected StringgetProperty(Iterator props, String name) Returns the value of the named property from an iterator of<property>elements.getRealm()Returns the logging realm.protected ScheduledThreadPoolExecutorLazily creates and returns aScheduledThreadPoolExecutorfor use by subclasses.Returns the Q2 server instance.intgetState()Returns the current state of this QBean.Returns the current state as a human-readable string.voidinit()init the servicebooleanReturnstrueif this QBean's configuration has been modified since last save.booleanrunning()Indicates whether this bean is currently starting or running.protected voidUpdates the value of the named attribute within an iterator of<attr>elements.voidConfigures this object with the suppliedConfiguration.voidSets the logger by name.voidsetModified(boolean modified) Marks this bean's persistent state as modified or in sync.voidSets the bean name.voidsetPersist(org.jdom2.Element persist) Sets the persistent configuration element.protected voidsetProperty(Iterator props, String name, String value) Updates the value attribute of the named property within an iterator of<property>elements.voidSets the logging realm.voidSets the Q2 server instance for this QBean.voidsetState(int state) Sets the lifecycle state of this bean.voidstart()start the servicevoidstop()stop the service
-
Field Details
-
THREAD_POOL_EXECUTOR__QBEAN_PREFIX
Prefix used when registering pooled executors inNameRegistrar.- See Also:
-
XML_CONFIG_ATTR__EXEC_SRV_TYPE
XML attribute selecting the executor type (fixed,cached,scheduled,single).- See Also:
-
XML_CONFIG_ATTR__EXEC_SRV_COREPOOLSIZE
XML attribute setting the executor's core pool size.- See Also:
-
XML_CONFIG_ATTR__EXEC_SRV_TERMINATION_TIMER
XML attribute setting the awaitTermination timeout, in seconds.- See Also:
-
DEFAULT_TERMINATION_TIMER
DefaultXML_CONFIG_ATTR__EXEC_SRV_TERMINATION_TIMERvalue, in seconds.- See Also:
-
-
Constructor Details
-
QThreadPoolExecutor
public QThreadPoolExecutor()Default constructor; no instance state to initialise.
-
-
Method Details
-
initService
Handle specific config elements type := "fixed" | "scheduled" | "cached" corePoolSize := integer (required for "fixed" and "scheduled" kinds, optional for "cached" kind)- Overrides:
initServicein classQBeanSupport- Throws:
Exception- on error
-
startService
Description copied from class:QBeanSupportCalled during the start lifecycle phase; subclasses may override.- Overrides:
startServicein classQBeanSupport- Throws:
Exception- on error
-
stopService
Description copied from class:QBeanSupportCalled during the stop lifecycle phase; subclasses may override.- Overrides:
stopServicein classQBeanSupport- Throws:
Exception- on error
-
getRegistrationName
Returns theNameRegistrarkey under which this bean's executor is registered.- Returns:
- the registration name (prefix concatenated with this bean's configured name)
-
getAttribute
protected org.jdom2.Attribute getAttribute(org.jdom2.Element elt, String attrName, boolean mandatory, String errDesc) throws ConfigurationException Returns a required or optional XML attribute, raising a configuration error witherrDescas context when a mandatory attribute is missing or empty.- Parameters:
elt- source elementattrName- attribute name to look upmandatory- iftrue, missing/empty attributes raise an exceptionerrDesc- human-readable description appended to the error message- Returns:
- the attribute, or
nullwhen not mandatory and absent - Throws:
ConfigurationException- if the attribute is mandatory and missing/empty
-
getThreadPoolExecutor
public static ThreadPoolExecutor getThreadPoolExecutor(String name) throws NameRegistrar.NotFoundException Retrieves a thread pool executor from NameRegistrar given its name.- Parameters:
name- bean name (without theTHREAD_POOL_EXECUTOR__QBEAN_PREFIXprefix)- Returns:
- the registered
ThreadPoolExecutor - Throws:
NameRegistrar.NotFoundException- if no executor is registered under that name
-
getThreadPoolExecutor
public static <T extends ThreadPoolExecutor> T getThreadPoolExecutor(String name, Class<T> clazz) throws NameRegistrar.NotFoundException Retrieves a thread pool executor from NameRegistrar given its name and expected class.- Type Parameters:
T- expected concrete executor type- Parameters:
name- bean name (without theTHREAD_POOL_EXECUTOR__QBEAN_PREFIXprefix)clazz- expected executor class- Returns:
- the registered executor, narrowed to
T - Throws:
NameRegistrar.NotFoundException- if no executor of the expected class is registered under that name
-
getExecSrvType
Description copied from interface:QThreadPoolExecutorMBeanReturns the executor service type.- Specified by:
getExecSrvTypein interfaceQThreadPoolExecutorMBean- Returns:
- executor service type
-
getTerminationTimer
Description copied from interface:QThreadPoolExecutorMBeanReturns the await-termination delay in milliseconds.- Specified by:
getTerminationTimerin interfaceQThreadPoolExecutorMBean- Returns:
- await termination delay
-
getActiveCount
Description copied from interface:QThreadPoolExecutorMBeanReturns the approximate number of threads that are actively executing tasks.- Specified by:
getActiveCountin interfaceQThreadPoolExecutorMBean- Returns:
- approximate number of threads that are actively executing tasks
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getCompletedTaskCount
Description copied from interface:QThreadPoolExecutorMBeanReturns the approximate total number of tasks that have completed execution.- Specified by:
getCompletedTaskCountin interfaceQThreadPoolExecutorMBean- Returns:
- the approximate total number of tasks that have completed execution.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getCorePoolSize
Description copied from interface:QThreadPoolExecutorMBeanReturns the core number of threads.- Specified by:
getCorePoolSizein interfaceQThreadPoolExecutorMBean- Returns:
- returns the core number of threads.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getKeepAliveTimeMS
Description copied from interface:QThreadPoolExecutorMBeanReturns the thread keep-alive time in milliseconds.- Specified by:
getKeepAliveTimeMSin interfaceQThreadPoolExecutorMBean- Returns:
- the thread keep-alive time, which is the amount of time (in milliseconds) which threads in excess of the core pool size may remain idle before being terminated
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getLargestPoolSize
Description copied from interface:QThreadPoolExecutorMBeanReturns the largest number of threads that have ever simultaneously been in the pool.- Specified by:
getLargestPoolSizein interfaceQThreadPoolExecutorMBean- Returns:
- the largest number of threads that have ever simultaneously been in the pool.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getMaximumPoolSize
Description copied from interface:QThreadPoolExecutorMBeanReturns the maximum allowed number of threads.- Specified by:
getMaximumPoolSizein interfaceQThreadPoolExecutorMBean- Returns:
- the maximum allowed number of threads.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getPoolSize
Description copied from interface:QThreadPoolExecutorMBeanReturns the current number of threads in the pool.- Specified by:
getPoolSizein interfaceQThreadPoolExecutorMBean- Returns:
- the current number of threads in the pool.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getTaskCount
Description copied from interface:QThreadPoolExecutorMBeanReturns the approximate total number of tasks that have been scheduled for execution.- Specified by:
getTaskCountin interfaceQThreadPoolExecutorMBean- Returns:
- the approximate total number of tasks that have been scheduled for execution
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
isShutdown
Description copied from interface:QThreadPoolExecutorMBeanReturns whether this executor has been shut down.- Specified by:
isShutdownin interfaceQThreadPoolExecutorMBean- Returns:
- true if this executor has been shut down.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
isTerminated
Description copied from interface:QThreadPoolExecutorMBeanReturns whether all tasks have completed following shut down.- Specified by:
isTerminatedin interfaceQThreadPoolExecutorMBean- Returns:
- true if all tasks have completed following shut down
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
isTerminating
Description copied from interface:QThreadPoolExecutorMBeanReturns whether this executor is in the process of terminating after shutdown.- Specified by:
isTerminatingin interfaceQThreadPoolExecutorMBean- Returns:
- true if this executor is in the process of terminating after shutdown or shutdownNow but has not completely terminated.
- Throws:
NameRegistrar.NotFoundException- if the executor cannot be found in the name registrar
-
getInitialCorePoolSize
Returns the core pool size requested at configuration time.- Returns:
- the initially configured core pool size
-
setExecSrvType
Sets the executor type (fixed,cached,scheduled, orsingle).- Parameters:
execSrvType- the new executor type
-
setInitialCorePoolSize
Sets the initial core pool size used when the executor is created.- Parameters:
initialCorePoolSize- core pool size
-
setTerminationTimer
Sets the awaitTermination timeout, in seconds.- Parameters:
terminationTimer- timeout used during shutdown
-