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?
So the ideal thread pool size is 4 cores * 2 * ( 1 + 9 ) = 80. If all 100ms are calculation, 0ms is waiting. the blocking coefficent is 0. The ideal thread pool size is 4 * 2 * 1 = 8.
By dividing the amount of thread by the seam length, we get the ratio of thread consumed. If we multiply this factor times the total length of seam, we can determine the total thread consumed for that seam.
using a thread pool that is too large or too small – if the thread pool contains too many threads, this can significantly affect the performance of the application; on the other hand, a thread pool that is too small may not bring the performance gain that you would expect.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With