Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Increase GC calls

 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I read on this forum that it is possible to increase the GC calls. However can not find how to do this in Tomcat5.5.

I opened the Tomcat5.5 Configuration Windows and went to the Java Tab. I set the maximum heap size and minimum heap size to 1024Mb (There are textfields in the bottom of the window for this).

However I can not find how to increase the GC calls. From whee can I ncrease the GC Calls? Also is this a good idea? would I be risking anything?

Thanks & Regards,
Sim085
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing specific in Tomcat for doing this.

You can always suggest that the JVM run Garbage Collection (GC) with System.gc().

Do you have a reason for wanting to do this?
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I read this on another post and got intrested because I believe it could help me solve a problem that I have been having.

Basically my application deployed on Tomcat was continuasly crashing (throwing different exceptions after some time). I now increased the Maximum Heap Size, and so far the system did not crash.

I do not think I have any memory leaks since I am not managing and database connection. All connections are managed by Hibernate (A Framework to persist objects with a relational database).

I thus assumed that my problem is comming because the garbage collection process is not running fast enough. I came to this assumption because when I use the system and load too many objects (with a small heap), the system crashes.

So basically I tought that maybe there could be an option in Java (or Tomcat) to run the GC more often.

ps: How can I know if my system has any memory leaks? Is there a tool or something?

Regards,
Sim085
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thus assumed that my problem is comming because the garbage collection process is not running fast enough.


Bad assumption. GC will always be run if the system can't find enough memory for a new object. If a memory exception is thrown you can be sure that the JVM has tried everything to find the space.

Bill
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how does it explain itself that the system is now not crashing once I increased the Heap Size?

Also is there any tool that I can use to monitor the memory being used by my Application? Whit such a tool I can see if my application is eating up memory. Thuis I would know if increasing the Heap Size just postponed the problem or else solved it!

Thanks for explaining me how the garbage collection works!

Regards,
Sim085
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how does it explain itself that the system is now not crashing once I increased the Heap Size?


Obviously, because at some point your app needs more memory than you expected for some reason.
There are a LOT of tools for looking at memory use.
You can use the java.lang.Runtime methods such as freeMemory() to log stuff for example.
I think recent threads in the forum have covered this topic, do some searches.
Bill
 
Simon Joseph Aquilina
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I definitly will

Regards,
Sim085
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic