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 Object
implements ExecutorConfiguration
Allows configuration
ExecutorService
instances that are made available as beans.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Number of available processors.protected String
protected Integer
Fields inherited from interface io.micronaut.scheduling.executor.ExecutorConfiguration
PREFIX, PREFIX_CONSUMER, PREFIX_IO, PREFIX_SCHEDULED
-
Constructor Summary
ModifierConstructorDescriptionprotected
UserExecutorConfiguration
(@Nullable String name, @Nullable Integer nThreads, @Nullable ExecutorType type, @Nullable Integer parallelism, @Nullable Integer corePoolSize, @Nullable Boolean virtual, @Nullable Class<? extends ThreadFactory> threadFactoryClass) Default Constructor. -
Method Summary
Modifier and TypeMethodDescriptiongetName()
Optional<Class<? extends ThreadFactory>>
getType()
boolean
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, @Nullable Class<? extends ThreadFactory> threadFactoryClass) Construct aUserExecutorConfiguration
for the givenExecutorType
.static UserExecutorConfiguration
of
(String name, ExecutorType type) Construct aUserExecutorConfiguration
for the givenExecutorType
.void
setCorePoolSize
(Integer corePoolSize) Sets the core pool size forExecutorType.SCHEDULED
.void
Sets the executor name.void
setNumberOfThreads
(Integer nThreads) Sets the number of threads forExecutorType.FIXED
.void
setParallelism
(Integer parallelism) Sets the parallelism forExecutorType.WORK_STEALING
.void
setThreadFactoryClass
(Class<? extends ThreadFactory> threadFactoryClass) Sets the thread factory class.void
setType
(ExecutorType type) Sets the executor type.void
setVirtual
(boolean virtual)
-
Field Details
-
AVAILABLE_PROCESSORS
public static final int AVAILABLE_PROCESSORSNumber of available processors. -
name
-
nThreads
-
-
Constructor Details
-
UserExecutorConfiguration
@ConfigurationInject protected UserExecutorConfiguration(@Nullable @Parameter @Nullable String name, @Nullable @Nullable Integer nThreads, @Nullable @Nullable ExecutorType type, @Nullable @Nullable Integer parallelism, @Nullable @Nullable Integer corePoolSize, @Nullable @Nullable Boolean virtual, @Nullable @Nullable Class<? extends ThreadFactory> threadFactoryClass) Default Constructor.- Parameters:
name
- the namenThreads
- number of threadstype
- the typeparallelism
- the parallelismcorePoolSize
- the core pool sizevirtual
- whether to use virtual threadsthreadFactoryClass
- the thread factory class
-
-
Method Details
-
getName
- Specified by:
getName
in interfaceExecutorConfiguration
- Returns:
- The name of the component
-
getType
- Specified by:
getType
in interfaceExecutorConfiguration
- Returns:
- The
ExecutorType
-
getParallelism
- Specified by:
getParallelism
in interfaceExecutorConfiguration
- Returns:
- The parallelism for
ExecutorType.WORK_STEALING
-
getNumberOfThreads
- Specified by:
getNumberOfThreads
in interfaceExecutorConfiguration
- Returns:
- The number of threads for
ExecutorType.FIXED
-
getCorePoolSize
- Specified by:
getCorePoolSize
in interfaceExecutorConfiguration
- Returns:
- The core pool size for
ExecutorType.SCHEDULED
-
isVirtual
public boolean isVirtual()- Specified by:
isVirtual
in interfaceExecutorConfiguration
- Returns:
- Whether the pool should use virtual threads.
-
setVirtual
public void setVirtual(boolean virtual) - Parameters:
virtual
- Whether the pool should use virtual threads
-
getThreadFactoryClass
- Specified by:
getThreadFactoryClass
in interfaceExecutorConfiguration
- Returns:
- The class to use as the
ThreadFactory
-
setName
Sets the executor name.- Parameters:
name
- The name
-
setType
Sets the executor type. Default value (ExecutorType.SCHEDULED
).- Parameters:
type
- The type
-
setParallelism
Sets the parallelism forExecutorType.WORK_STEALING
. Default value (Number of processors available to the Java virtual machine).- Parameters:
parallelism
- The parallelism
-
setNumberOfThreads
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
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
Sets the thread factory class.- Parameters:
threadFactoryClass
- The thread factory class.
-
of
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
type
- The type- Returns:
- The configuration
-
of
Construct aUserExecutorConfiguration
for the givenExecutorType
.- Parameters:
name
- The nametype
- The type- Returns:
- The configuration
-
of
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 @Nullable Class<? extends 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
-