Package io.micronaut.scheduling.executor
Class UserExecutorConfiguration
- java.lang.Object
-
- io.micronaut.scheduling.executor.UserExecutorConfiguration
-
- All Implemented Interfaces:
ExecutorConfiguration
@EachProperty("micronaut.executors") public class UserExecutorConfiguration extends java.lang.Object implements ExecutorConfiguration
Allows configurationExecutorService
instances that are made available as beans.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static int
AVAILABLE_PROCESSORS
Number of available processors.protected java.lang.String
name
protected java.lang.Integer
nThreads
-
Fields inherited from interface io.micronaut.scheduling.executor.ExecutorConfiguration
PREFIX, PREFIX_CONSUMER, PREFIX_IO, PREFIX_SCHEDULED
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
UserExecutorConfiguration(java.lang.String name, java.lang.Integer nThreads, ExecutorType type, java.lang.Integer parallelism, java.lang.Integer corePoolSize, java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Default Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @Min(1L) java.lang.Integer
getCorePoolSize()
java.lang.String
getName()
@Min(1L) java.lang.Integer
getNumberOfThreads()
@Min(1L) java.lang.Integer
getParallelism()
java.util.Optional<java.lang.Class<? extends java.util.concurrent.ThreadFactory>>
getThreadFactoryClass()
ExecutorType
getType()
static UserExecutorConfiguration
of(ExecutorType type)
Construct aUserExecutorConfiguration
for the givenExecutorType
.static UserExecutorConfiguration
of(ExecutorType type, int num)
Construct aUserExecutorConfiguration
for the givenExecutorType
.static UserExecutorConfiguration
of(ExecutorType type, int num, java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Construct aUserExecutorConfiguration
for the givenExecutorType
.static UserExecutorConfiguration
of(java.lang.String name, ExecutorType type)
Construct aUserExecutorConfiguration
for the givenExecutorType
.void
setCorePoolSize(java.lang.Integer corePoolSize)
Sets the core pool size forExecutorType.SCHEDULED
.void
setName(java.lang.String name)
Sets the executor name.void
setNumberOfThreads(java.lang.Integer nThreads)
Sets the number of threads forExecutorType.FIXED
.void
setParallelism(java.lang.Integer parallelism)
Sets the parallelism forExecutorType.WORK_STEALING
.void
setThreadFactoryClass(java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Sets the thread factory class.void
setType(ExecutorType type)
Sets the executor type.
-
-
-
Constructor Detail
-
UserExecutorConfiguration
@ConfigurationInject protected UserExecutorConfiguration(@Nullable @Parameter java.lang.String name, @Nullable java.lang.Integer nThreads, @Nullable ExecutorType type, @Nullable java.lang.Integer parallelism, @Nullable java.lang.Integer corePoolSize, @Nullable java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Default Constructor.- Parameters:
name
- the namenThreads
- number of threadstype
- the typeparallelism
- the parallelismcorePoolSize
- the core pool sizethreadFactoryClass
- the thread factory class
-
-
Method Detail
-
getName
@NonNull public java.lang.String getName()
- Specified by:
getName
in interfaceExecutorConfiguration
- Returns:
- The name of the component
-
getType
public ExecutorType getType()
- Specified by:
getType
in interfaceExecutorConfiguration
- Returns:
- The
ExecutorType
-
getParallelism
@Min(1L) public @Min(1L) java.lang.Integer getParallelism()
- Specified by:
getParallelism
in interfaceExecutorConfiguration
- Returns:
- The parallelism for
ExecutorType.WORK_STEALING
-
getNumberOfThreads
@Min(1L) public @Min(1L) java.lang.Integer getNumberOfThreads()
- Specified by:
getNumberOfThreads
in interfaceExecutorConfiguration
- Returns:
- The number of threads for
ExecutorType.FIXED
-
getCorePoolSize
@Min(1L) public @Min(1L) java.lang.Integer getCorePoolSize()
- Specified by:
getCorePoolSize
in interfaceExecutorConfiguration
- Returns:
- The core pool size for
ExecutorType.SCHEDULED
-
getThreadFactoryClass
public java.util.Optional<java.lang.Class<? extends java.util.concurrent.ThreadFactory>> getThreadFactoryClass()
- Specified by:
getThreadFactoryClass
in interfaceExecutorConfiguration
- Returns:
- The class to use as the
ThreadFactory
-
setName
public void setName(java.lang.String name)
Sets the executor name.- Parameters:
name
- The name
-
setType
public void setType(ExecutorType type)
Sets the executor type. Default value (ExecutorType.SCHEDULED
).- Parameters:
type
- The type
-
setParallelism
public void setParallelism(java.lang.Integer parallelism)
Sets the parallelism forExecutorType.WORK_STEALING
. Default value (Number of processors available to the Java virtual machine).- Parameters:
parallelism
- The parallelism
-
setNumberOfThreads
public void setNumberOfThreads(java.lang.Integer nThreads)
Sets the number of threads forExecutorType.FIXED
. Default value (2 * Number of processors available to the Java virtual machine).- Parameters:
nThreads
- The number of threads
-
setCorePoolSize
public void setCorePoolSize(java.lang.Integer corePoolSize)
Sets the core pool size forExecutorType.SCHEDULED
. Default value (2 * Number of processors available to the Java virtual machine).- Parameters:
corePoolSize
- The core pool size
-
setThreadFactoryClass
public void setThreadFactoryClass(java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Sets the thread factory class.- Parameters:
threadFactoryClass
- The thread factory class.
-
of
public static UserExecutorConfiguration of(ExecutorType type)
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
type
- The type- Returns:
- The configuration
-
of
public static UserExecutorConfiguration of(java.lang.String name, ExecutorType type)
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
name
- The nametype
- The type- Returns:
- The configuration
-
of
public static UserExecutorConfiguration of(ExecutorType type, int num)
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
type
- The typenum
- The number of threads forExecutorType.FIXED
or the parallelism forExecutorType.WORK_STEALING
or the core pool size forExecutorType.SCHEDULED
- Returns:
- The configuration
-
of
public static UserExecutorConfiguration of(ExecutorType type, int num, @Nullable java.lang.Class<? extends java.util.concurrent.ThreadFactory> threadFactoryClass)
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
type
- The typenum
- The number of threads forExecutorType.FIXED
or the parallelism forExecutorType.WORK_STEALING
or the core pool size forExecutorType.SCHEDULED
threadFactoryClass
- The thread factory class- Returns:
- The configuration
-
-