To invoke the garbage collector explicitly we use Runtime.getRuntime().gc() But what is the priority of garbage collector thread?
I have heard it runs on a low priority if there are multiple threads running which are creating a lot objects simultaneously then even if i invoke GC thread it doesn't get so much CPU time and objects doesn't get collected and sometimes get out of memory exception.
So is there a way to increase garbage collector thread priority so that it runs and collects all those objects which are going out of scope while the program is still running with all rest of the threads active?
Calling gc() does not explicitly execute the garbage collector. It suggests to the JVM that now would be a good time for some GC. The JVM may do a full GC, a bit of GC, or no GC at all, in response.
Some of your concerns are unfounded. Particularly, you will never get an OutOfMemoryError when there exist objects that could be garbage collected, and would free enough memory to allow execution to continue.
Tweaking the garbage collector is possible, to achieve better performance (for various definitions of "better"). However, it is an advanced topic (one that I am not all that expert in ). Only very rarely does it involve calling gc() - that's usually pointless. There is no direct way to change the GC thread priority, but you can adjust a variety of settings.
From the questions you are asking, I detect that you probably aren't at the stage where you should be worrying about it. For 99% of simple Java applications, the GC just happens and all is fine. [ January 29, 2008: Message edited by: Peter Chase ]
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.