Package io.micronaut.scheduling.executor
Class ExecutorFactory
java.lang.Object
io.micronaut.scheduling.executor.ExecutorFactory
- All Implemented Interfaces:
GracefulShutdownCapable
Constructs
ExecutorService instances based on UserExecutorConfiguration instances.- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ThreadFactoryeventLoopGroupThreadFactory(ExecutorConfiguration configuration) Constructs an executor thread factory.executorService(ExecutorConfiguration executorConfiguration) Create the ExecutorService with the given configuration.After a call toGracefulShutdownCapable.shutdownGracefully()report the state of the shutdown.Trigger a graceful shutdown.
-
Constructor Details
-
ExecutorFactory
- Parameters:
beanLocator- The bean beanLocatorthreadFactory- The factory to create new threads- Since:
- 2.0.1
-
-
Method Details
-
eventLoopGroupThreadFactory
@EachBean(ExecutorConfiguration.class) protected ThreadFactory eventLoopGroupThreadFactory(ExecutorConfiguration configuration) Constructs an executor thread factory.- Parameters:
configuration- The configuration- Returns:
- The thread factory
-
executorService
@EachBean(ExecutorConfiguration.class) @Bean(preDestroy="shutdown") public ExecutorService executorService(ExecutorConfiguration executorConfiguration) Create the ExecutorService with the given configuration.- Parameters:
executorConfiguration- The configuration to create a thread pool that creates new threads as needed- Returns:
- A thread pool that creates new threads as needed
-
shutdownGracefully
Description copied from interface:GracefulShutdownCapableTrigger a graceful shutdown. The returnedCompletionStagewill complete when the shutdown is complete.Note that the completion of the returned future may be user-dependent. If a user does not close their connection, the future may never terminate. Always add a timeout for a hard shutdown.
This method should not throw an exception, nor should the returned stage complete exceptionally. Just log an error instead.
- Specified by:
shutdownGracefullyin interfaceGracefulShutdownCapable- Returns:
- A future that completes when this bean is fully shut down
-
reportActiveTasks
Description copied from interface:GracefulShutdownCapableAfter a call toGracefulShutdownCapable.shutdownGracefully()report the state of the shutdown. IfGracefulShutdownCapable.shutdownGracefully()has not been called the behavior of this method is undefined.- Specified by:
reportActiveTasksin interfaceGracefulShutdownCapable- Returns:
- The current number of still-active tasks before the shutdown completes, or
Optional.empty()if no state can be reported
-