Reputation: 581
I have the below code .Can I change the ThreadPoolExecutor thread number size at run time ? I am using spring boot.
@Configuration
public class ExecutorConfig
{
@Value(numberOfThreads)
private String numberOfThreads ; // numberOfThreads is configured app.properties file
@Bean
public ThreadPoolExecutor executorConfig()
{
ThreadPoolExecutor e = Executors.newFixedThreadPool(numberOfThreads);
return e;
}
}
Upvotes: 0
Views: 5427
Reputation: 187
One option is to add a set method for the property numberOfThread and then provide a way to update it, like a new endpoint. But if your app restarts it will still get the previous value from application.properties.
Other option is to use Spring Cloud Config, but this may or may not be overkill for your case.
Also, this answer goes a bit deeper with some code examples to force a reload.
Upvotes: 1