I'm using a thread pool that should be able to execute hundreds of concurrent tasks. However the tasks usually do very little computation and spend most of their time waiting on some server response. So if the thread pool size contains hundreds of threads just a few of them will be active while most of them will be waiting.
I know in general this is not a good practice for thread pools usage but the current design does not permit making my tasks asynchronous so that they can return the control without waiting for the server's response. So given this limitation I guess my biggest problem is increased memory consumption for the threads stack space.
So is there any way to use some kind of light-weight threads that does not consume much memory?
I now there's a JVM option -Xss to control the stacks memory but it's seems there's no way to control this per thread pool or thread only as opposed to changing it for all the threads inside the VM, right?
Also do you have any suggestions for a better solution to my problem?