• 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

Java Heap size error keeps coming

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

I started getting "java.lang.OutOfMemoryError: Java heap space" when my application starts up in Tomcat. As suggested I modified the catalina.bat file (running on Windows, not as service) and added the following...

set CATALINA_OPTS=-Xms256m -Xmx1024m

But the error keeps coming. I am not sure if this is because I did not configure the batch file correctly or because my app really needs even more memory than this.

Is there anyway to make Tomcat print out how much memory it has? Or else do you have any other suggestions on how to make this error go way?

Thanks in advance for any help.
 
Ranch Hand
Posts: 75
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

set CATALINA_OPTS=-Xms256m -Xmx1024m



try:
set CATALINA_OPTS="-Xms256m -Xmx1024m"

if that doesn't help, try to increase -Xmx to as much as you can on your machine, and see if it's still failing with OOM. If it does, it's a big chance that your tomcat ignore CATALINA_OPTS from your bat script. How do you starting your tomcat, using bat or running tomcat as service?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If Tomcat starts and runs just fine until you try to access your application, then we know where to look for the problem.

Java provides methods in the java.lang.Runtime class to get at memory related information.

For some reason your application requires more memory than you have alloted.

Common errors include creating loops or recursion that add objects but never exits.

Does your app even run once before hitting the memory error?

Bill

 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not recommend modifying catalina.bat. Add a file named "setenv.bat" to your Tomcat bin directory and put the SET statement in there. Catalina.bat looks for that file and uses it, if it finds it.

As far as getting memory stats goes, there are a number of ways to look. The jconsole app is one of the most basic ones. Tomcat should list memory usage in its management webapps. There are others, but these are probably the 2 easiest to get started with.
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic