Reasonable number of threads for thread pool running web service requests

mgamer picture mgamer · Jun 22, 2009 · Viewed 9.5k times · Source

When creating an FixedThreadPool Executor object in Java you need to pass an argument describing the number of threads that the Executor can execute concurrently. I'm building a service class that's responsibility is to process a large collections of phone numbers. For each phone number I need to execute web service (that's my bottleneck) and then save response in a hashmap.

To make this bottleneck less harmful to the performance of my service I've decided to create Worker class which fetches unprocessed elements and processes them. Worker class implements Runnable interface and I run Workers using Executor.

The number of Workers that can be run in the same time depends on the size of Executor FixedThreadPool. What is the safe size for a ThreadPool? What can happen when I create FixedTheradPool with some big number as an argument?

Answer

Lars Andren picture Lars Andren · Jul 12, 2010

Something that could be considered is looking at

Runtime.getRuntime().availableProcessors()

which gives some direction on how many threads that would make sense for the system.