15

This is the error I get when I run my web application in an instance of the Tomcat servlet container started by NetBeans. To fix this I even changed the heap size in netbeans.conf, but still it shows the same error. How can I keep this from happening?

HTTP Status 500 - 

--------------------------------------------------------------------------------

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)


root cause 

java.lang.OutOfMemoryError: Java heap space

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
trincot
  • 317,000
  • 35
  • 244
  • 286
  • http://stackoverflow.com/questions/705605/java-heap-space-in-netbeans-but-ive-increased-the-heap-size-already – erickson Apr 04 '09 at 19:22
  • http://stackoverflow.com/questions/673646/how-can-i-prevent-permgen-space-errors-in-netbeans – Steen Apr 12 '11 at 18:24
  • the righter answer to this question is actually http://stackoverflow.com/questions/717550/java-lang-outofmemoryerror-java-heap-space-with-netbeans/721281#721281. The heavily upvoted answer is a good answer for a different question. – vkraemer Jun 15 '11 at 17:56

5 Answers5

30

Changing the heap size in netbeans.conf only changes the heap for NetBeans itself, not for applications run through NetBeans.

The correct way is to right-click on the project and select "Properties" and then "Run"; there you can set the VM options appropriately (-Xmx256m, for instance). It should look something like this:

setting the heap size
(Thanks to VonC for finding this picture.)

Community
  • 1
  • 1
Michael Myers
  • 188,989
  • 46
  • 291
  • 292
  • True. +1. Although, would I have been the one writing this answer, I would have included the picture http://www.javapassion.com/handsonlabs/nbprofilermemory/index_files/3_heap17.png , from http://www.javapassion.com/handsonlabs/nbprofilermemory/ ;) (but that's just me: I always include picture) – VonC Apr 04 '09 at 18:32
  • "I always include picture": as you have noticed lately: http://stackoverflow.com/questions/707194#707206 (in the comments) – VonC Apr 04 '09 at 18:36
  • How do you find appropriate pictures, though? I tried to find a screenshot and couldn't. – Michael Myers Apr 04 '09 at 18:45
  • The problem is that,there is no VM options in the run category of the project properties.So,im struck up there again!! –  Apr 05 '09 at 04:24
  • @divya: Could you give us a screenshot or something? I have all the web application plugins uninstalled right now, so I can't easily reproduce your problem. – Michael Myers Apr 05 '09 at 04:51
  • 1
    I don't think this applies to Servlet Projects... only desktop projects. – James Schek Apr 07 '09 at 00:31
  • @James Schek: Apparently you're right, judging by divya's post below. – Michael Myers Apr 07 '09 at 00:41
9

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,

set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)

In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options.

What is the difference between CATALINA_OPTS and JAVA_OPTS?

The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don't want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.

How to set java heap size in JBoss?

Stop JBoss server, edit $JBOSS_HOME/bin/run.conf, and then restart JBoss server. You can change the line with JAVA_OPTS to something like:

JAVA_OPTS="-server -Xms128m -Xmx128m"

How to set java heap size in Eclipse? You have 2 options:

  1. Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.

    -vmargs-Xms64m-Xmx256m

  2. Or, you can just run eclipse command with additional options at the very end. Anything after -vmargs will be treated as JVM options and passed directly to the JVM. JVM options specified in the command line this way will always override those in eclipse.ini. For example,

    eclipse -vmargs -Xms64m -Xmx256m

How to set java heap size in NetBeans?

Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf. For example,

netbeans_default_options="-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none

How to set java heap size in Apache Ant?

Set environment variable ANT_OPTS. Look at the file $ANT_HOME/bin/ant or %ANT_HOME%\bin\ant.bat, for how this variable is used by Ant runtime.

set ANT_OPTS="-Xms512m -Xmx512m" (Windows)export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh) 
wickedone
  • 542
  • 1
  • 6
  • 18
Rakesh
  • 91
  • 1
  • 1
7

If you increase the virtual memory of your Tomcat server then it will be OK.

Steps:

  1. In NB go through the windows menu and add Services
  2. You will find Tomcat in the services. Right click on Tomcat server and select Properties
  3. Go to the platform in the properties and write -Xms512m in VM options field
Community
  • 1
  • 1
  • 1
    This answer describes how to reconfigure the Java process that NetBeans creates to run the Tomcat servlet container, which is the JVM that is running out of memory. – vkraemer Jun 15 '11 at 17:49
5

I'm guessing that increasing the memory won't fix the problem. What is that MonitorFilter doing? What's eating up all that memory?

Your best bet is to figure that out. If this is a web app, see if you can turn off that filter and run without it. If you have success, you know that the MonitorFilter is causing your to fail.

duffymo
  • 305,152
  • 44
  • 369
  • 561
3

This has nothing to do with NetBeans (well, perhaps), rather it has to do with Tomcat. Tomcat is the process that is running out of heap, not NetBeans. Track down the startup process for your Tomcat. If it's bundled with NB, then Tomcat is buried within the NB installation, check for an "enterpriseN" directory, N being a number, Tomcat is probably in there and it's a rather generic distribution of it.

As to why the monitor is run OOM, that's hard to say, it's a pretty simple process when you think about it. You can also try disabling HTTP monitoring to see if it's a problem with the Monitoring itself or something with your application.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203