• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Garbage Collector Priority  RSS feed

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • 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 ]
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!