Q:

Changing number of threads in Pooling connection manager in java at runtime

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.

A:

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.

Calls to execute will reuse previously constructed threads if
  available. If no existing thread is available, a new thread will be
  created and added to the pool. Threads that have not been used for
  sixty seconds are terminated and removed from the cache.

