I have an executor set up to be invoked via bean.
@Configuration
public class ExecutorConfiguration {
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public ScheduledExecutorService jobExecutor(@Value("${scheduler.jobs}") Integer jobs) {
return Executors.newScheduledThreadPool(jobs);
}
}
I control the shutdown operation of this executor via user input. Once shutdown, this executor will not start back up (no option for restart or submit new tasks).
Hence I want to re-instantiate the bean with a new executor. But only if the existing executor isShutdown() (I can check whether its shutdown or not)
How can I achieve this via Spring Boot? Or should I manually create an executor at runtime without the spring way (i.e., create a POJO singleton executor)