I am working on a Spring Boot application where I use a ThreadPoolTaskExecutor to handle background tasks. Currently, the thread pool size is configured in application.properties, like this:
spring.task.execution.pool.core-size=10
spring.task.execution.pool.max-size=20
I want to dynamically adjust the core and max pool size at runtime based on system load, without restarting the application.
I have tried accessing the executor bean and using setCorePoolSize() and setMaxPoolSize(), but I am not sure if this is safe, and how to ensure that tasks already running are not interrupted.
Is there a recommended approach to safely change thread pool size dynamically?
Are there any Spring Boot-specific utilities for this?
How can I monitor the thread pool usage in real-time?