• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Garbage Collector Priority

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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?
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMHO, this is not an appropriate forum.
This link has good information on tuning garbage collection, if you are interested.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic