I am trying to implement a project which uses ThreadSafeClientConnManager, with 20 as a maximum threads in the pool. Now, depending on the traffic, I want to change the number of threads at runtime. Is it possible to do it?
I have one solution that could work is, I have a new set of threadpool which I initialize when changing the max connections, and then replace the existing one. Kind of buffer switch. but I am not sure if that is the optimal solution.
I assume that now you are using
Executors.newFixedThreadPool. This pool cannot be resized dynamically, unfortunately.A better solution that is adaptive would be the
Executors.newCachedThreadPool. Take a look at the javadoc.