I have a java program which listens on a port for input. Based on Input, it calls a webservice and then returns a success/failure back to the client program.
I fork a thread for each client connection. The response back to the client which connects to the program has to be quick.
These are the choices I am considering
- use regular threads
The reason I am considering Pools is because my threads are shortlived - they just call a webservice, return result to the client and close the connection.
I don't think
newFixedThreadPool would be the right thing because then connections would be waiting in queues to get a thread.
newCachedThreadPool would have been perfect except for one thing - threads die after a minute. In my case, I get bursts of connections - i.e. multiple connections and then there may be a lull for a few minutes and then again bursts. I think the threads in the CachedThreadPool would die and and would again have to be recreated - so in this case, it may work like #1 sometimes.
Ideally I would have loved to have
newCachedThreadPool with a minimum - i.e. a setting which says number of threads would never go below say 20. So idle threads are killed but never allow to go below a minimum threshold.
Is there anything like this available? Or are there any better alternatives?