This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am facing interesting behavior when working with threads in Java. I would like to ask for explanation of this behavior.
Let's say we have graph (in terms of graphs theory) with 220 vertexes. We are iterating through this graph. When visiting vertex, we start
thread to generate an image.
We can set number of threads used to generate images in general.
If I use only two threads for generating images, memory management is much worse than eg. 20 threads (Out of memory exceptions etc.
3GB not enough) 20 threads run is OK, using approx 2GB. That's smt. I don't understand. This doesn't make sense. Intuitively using 20 threads memory
management should be worse because every thread needs it's own memory to generate an image (in the same time).
Only one theory I have is that this is related to how often is GC called when using 2 or 20 threads.
I think we don't have enough information. It depends on what data is generated where. Could be a producer thread creating data that gets stored, waiting to be processed. But with 2 threads it is being generated faster than processed to it backs up.