We are currently trying to tune performance using multithreading in our java application. We have a long serial task, which we would like to divide into multiprocessor cores.
Basically, we have a list that allows you to say 100,000 items / things that need to be done.
Now my question is: is it better to do this:
Option 1 (pseudo-code):
for(i = 0; i < 100000; i++){ threadpool.submit(new MyCallable("1 thing to do")) }
This would add 100,000 runnables / callables to the threadpool queue (current LinkedBlockingQueue)
or better to do: Option 2 (pseudocode)
for(i = 0; i < 4; i++){ threadpool.submit(new MyCallable("25000 things to do")) }
We already tried option 1, and we did not notice any performance improvement, although we can clearly see that several threads work like crazy, as well as 4 processor cores. But I feel that option 1 has some overhead due to a lot of tasks. We have not tried option 2 yet, but I feel that it can speed things up because the overhead is less. We basically break the list into 4 large pieces instead of 100,000 individual items.
Any thoughts on this?
thanks
source share