0

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by purijatin
0

They are not eligible for GC, with or without "line 5", as the "Runnables" are still referenced in the queue.

0

very true, actually incomplete code,
assume that i am taking the element out of the queue.
and then running it. Then the previous runnable will be eligible for gc

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.