Hello,
The problem is that some how due to garbage collection timings I am having tradeoff's in my performance. The issue can be generalized as:
public void loop(BlockingQueue<Runnable> queue)
{
for(Runnable runnable : queue)//line2
{
runnable.run();//line4
if(Math.random() > 0.9) System.gc();//line5
}
//line7
}
Now normally the queue passed as argument will contain more than 40,000 elements normally.
And because I am iterating over the queue in a loop, even though the already 'run' objects are out of scope, they are still not available for garbage Collection because they are in invisible state. hence if i do not have the line 5, then suddenly there will be a huge load on the garbage collector when the method goes out of the stack. Imagine if concurrently many thread accessing the menthod.
1st Question) Is line 5 needed? Any other substitute
2nd Question) If I have to have line 5, i found out the performance was very very bad when compared to not having it.
ultimately garbage collection has to happen? Now when it should happen, I am unable to figure out