Package org.apache.sling.commons.threads
Class ModifiableThreadPoolConfig
java.lang.Object
org.apache.sling.commons.threads.ModifiableThreadPoolConfig
- All Implemented Interfaces:
ThreadPoolConfig
@ProviderType
public final class ModifiableThreadPoolConfig
extends Object
implements ThreadPoolConfig
This is a modifiable thread pool configuration that can be instantiated
and then configured to create a new thread pool.
The default values for this configuration are:
- min pool size: 5
- max pool size: 5
- queue size: -1
- keep alive time: 60000
- block policy: RUN
- shutdown graceful: true
- shutdown wait time: -1
- priority: NORM
- daemon: false
- factory: null (= default jvm thread factory)
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.sling.commons.threads.ThreadPoolConfig
ThreadPoolConfig.ThreadPoolPolicy, ThreadPoolConfig.ThreadPriority -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration property for the block policy.static final StringConfiguration property for the daemon flag.static final StringConfiguration property for the keep alive time.static final StringConfiguration property for the max pool size.static final StringConfiguration property for the max thread age.static final StringConfiguration property for the min pool size.static final StringConfiguration property for the thread pool name.static final StringConfiguration property for the priority.static final StringConfiguration property for the queue size.static final StringConfiguration property for the shutdown graceful flag.static final StringConfiguration property for the shutdown wait time. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new default configuration.Clone an existing configuration -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturn the block policy.Return the thread pool factory.longReturn the keep alive time.intReturn the maximum pool sizelongReturn the maximum age before a thread is retired.intReturn the minimum pool size.Return the priority for the threads.intReturn the queue size.intReturn the shutdown wait time in ms.inthashCode()booleanisDaemon()Return if daemon threads should be created.booleanShould this pool shutdown graceful.voidsetBlockPolicy(ThreadPoolConfig.ThreadPoolPolicy blockPolicy) Set the block policy.voidsetDaemon(boolean isDaemon) Set the daemon handling.voidsetFactory(ThreadFactory factory) Set the thread factory.voidsetKeepAliveTime(long keepAliveTime) Set the keep alive time.voidsetMaxPoolSize(int maxPoolSize) Set the max pool size.voidsetMaxThreadAge(long maxThreadAge) Deprecated.Since version 3.4.0 should no longer be called, as threads are no longer retired but instead the thread locals are cleaned up (SLING-6261)voidsetMinPoolSize(int minPoolSize) Set the min pool size.voidsetPriority(ThreadPoolConfig.ThreadPriority priority) Set the thread priority.voidsetQueueSize(int queueSize) Set the queue size.voidsetShutdownGraceful(boolean shutdownGraceful) Set if the pool should be shutdown graceful.voidsetShutdownWaitTimeMs(int shutdownWaitTimeMs) Set the shutdown wait time.
-
Field Details
-
PROPERTY_MIN_POOL_SIZE
Configuration property for the min pool size.- See Also:
-
PROPERTY_MAX_POOL_SIZE
Configuration property for the max pool size.- See Also:
-
PROPERTY_QUEUE_SIZE
Configuration property for the queue size.- See Also:
-
PROPERTY_MAX_THREAD_AGE
Configuration property for the max thread age.- See Also:
-
PROPERTY_KEEP_ALIVE_TIME
Configuration property for the keep alive time.- See Also:
-
PROPERTY_BLOCK_POLICY
Configuration property for the block policy.- See Also:
-
PROPERTY_SHUTDOWN_GRACEFUL
Configuration property for the shutdown graceful flag.- See Also:
-
PROPERTY_SHUTDOWN_WAIT_TIME
Configuration property for the shutdown wait time.- See Also:
-
PROPERTY_PRIORITY
Configuration property for the priority.- See Also:
-
PROPERTY_DAEMON
Configuration property for the daemon flag.- See Also:
-
PROPERTY_NAME
Configuration property for the thread pool name.- See Also:
-
-
Constructor Details
-
ModifiableThreadPoolConfig
public ModifiableThreadPoolConfig()Create a new default configuration. -
ModifiableThreadPoolConfig
Clone an existing configuration- Parameters:
copy- The config to clone
-
-
Method Details
-
getMinPoolSize
public int getMinPoolSize()Description copied from interface:ThreadPoolConfigReturn the minimum pool size.- Specified by:
getMinPoolSizein interfaceThreadPoolConfig- Returns:
- The minimum pool size.
- See Also:
-
setMinPoolSize
public void setMinPoolSize(int minPoolSize) Set the min pool size.- Parameters:
minPoolSize- New min pool size.
-
getMaxPoolSize
public int getMaxPoolSize()Description copied from interface:ThreadPoolConfigReturn the maximum pool size- Specified by:
getMaxPoolSizein interfaceThreadPoolConfig- Returns:
- The maximum pool size.
- See Also:
-
setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize) Set the max pool size.- Parameters:
maxPoolSize- New max pool size.
-
getQueueSize
public int getQueueSize()Description copied from interface:ThreadPoolConfigReturn the queue size.- Specified by:
getQueueSizein interfaceThreadPoolConfig- Returns:
- The queue size.
- See Also:
-
setQueueSize
public void setQueueSize(int queueSize) Set the queue size.- Parameters:
queueSize- New queue size.
-
getMaxThreadAge
public long getMaxThreadAge()Description copied from interface:ThreadPoolConfigReturn the maximum age before a thread is retired.- Specified by:
getMaxThreadAgein interfaceThreadPoolConfig- Returns:
- The maximum age of a thread in milliseconds.
-
setMaxThreadAge
public void setMaxThreadAge(long maxThreadAge) Deprecated.Since version 3.4.0 should no longer be called, as threads are no longer retired but instead the thread locals are cleaned up (SLING-6261)Set the max thread age.- Parameters:
maxThreadAge- New max thread age in milliseconds.
-
getKeepAliveTime
public long getKeepAliveTime()Description copied from interface:ThreadPoolConfigReturn the keep alive time.- Specified by:
getKeepAliveTimein interfaceThreadPoolConfig- Returns:
- The keep alive time.
- See Also:
-
setKeepAliveTime
public void setKeepAliveTime(long keepAliveTime) Set the keep alive time.- Parameters:
keepAliveTime- New keep alive time.
-
getBlockPolicy
Description copied from interface:ThreadPoolConfigReturn the block policy.- Specified by:
getBlockPolicyin interfaceThreadPoolConfig- Returns:
- The block policy.
- See Also:
-
setBlockPolicy
Set the block policy.- Parameters:
blockPolicy- The new block policy.- Throws:
IllegalArgumentException- If blockPolicy is null.
-
isShutdownGraceful
public boolean isShutdownGraceful()Description copied from interface:ThreadPoolConfigShould this pool shutdown graceful.- Specified by:
isShutdownGracefulin interfaceThreadPoolConfig- Returns:
trueif the pool should shutdown graceful.- See Also:
-
setShutdownGraceful
public void setShutdownGraceful(boolean shutdownGraceful) Set if the pool should be shutdown graceful.- Parameters:
shutdownGraceful- The shutdown graceful setting.
-
getShutdownWaitTimeMs
public int getShutdownWaitTimeMs()Description copied from interface:ThreadPoolConfigReturn the shutdown wait time in ms. A value below 1 means no waiting at shutdown.- Specified by:
getShutdownWaitTimeMsin interfaceThreadPoolConfig- Returns:
- The shutdown wait time in ms.
- See Also:
-
setShutdownWaitTimeMs
public void setShutdownWaitTimeMs(int shutdownWaitTimeMs) Set the shutdown wait time.- Parameters:
shutdownWaitTimeMs- The new shutdown wait time.
-
getFactory
Description copied from interface:ThreadPoolConfigReturn the thread pool factory. A value of null means the default jvm thread pool factory is used.- Specified by:
getFactoryin interfaceThreadPoolConfig- Returns:
- The thread pool factory or
null - See Also:
-
setFactory
Set the thread factory.- Parameters:
factory- The thread factory to be used ornullto use the default thread factory.
-
getPriority
Description copied from interface:ThreadPoolConfigReturn the priority for the threads.- Specified by:
getPriorityin interfaceThreadPoolConfig- Returns:
- The priority for the threads.
- See Also:
-
setPriority
Set the thread priority.- Parameters:
priority- The thread priority.- Throws:
IllegalArgumentException- If priority is null.
-
isDaemon
public boolean isDaemon()Description copied from interface:ThreadPoolConfigReturn if daemon threads should be created.- Specified by:
isDaemonin interfaceThreadPoolConfig- Returns:
trueif daemon threads should be created.- See Also:
-
setDaemon
public void setDaemon(boolean isDaemon) Set the daemon handling.- Parameters:
isDaemon- The daemon setting.
-
equals
-
hashCode
public int hashCode()
-