简体   繁体   English

java.lang.OutOfMemoryError:使用 NetBeans 的 Java 堆空间

[英]java.lang.OutOfMemoryError: Java heap space with NetBeans

This is the error I get when I run my web application in an instance of the Tomcat servlet container started by NetBeans.这是我在 NetBeans 启动的 Tomcat servlet 容器实例中运行 Web 应用程序时遇到的错误。 To fix this I even changed the heap size in netbeans.conf, but still it shows the same error.为了解决这个问题,我什至在 netbeans.conf 中更改了堆大小,但它仍然显示相同的错误。 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.

Changing the heap size in netbeans.conf only changes the heap for NetBeans itself, not for applications run through NetBeans.在 netbeans.conf 中更改堆大小只会更改 NetBeans 本身的堆,而不会更改通过 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).在那里您可以适当地设置 VM 选项(例如-Xmx256m )。 It should look something like this:它应该是这样的:

设置堆大小
(Thanks to VonC for finding this picture.) (感谢VonC找到这张图片。)

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat.停止Tomcat服务器,设置环境变量CATALINA_OPTS,然后重启Tomcat。 Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used.查看文件tomcat-install/bin/catalina.shcatalina.bat了解如何使用此变量。 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.catalina.batcatallina.sh ,您可能已经注意到 CATALINA_OPTS、JAVA_OPTS 或两者都可用于指定 Tomcat JVM 选项。

What is the difference between CATALINA_OPTS and JAVA_OPTS? CATALINA_OPTS 和 JAVA_OPTS 有什么区别?

The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (eg, JBoss). CATALINA_OPTS 名称专用于 Tomcat servlet 容器,而 JAVA_OPTS 可能被其他 Java 应用程序(例如,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.由于环境变量由所有应用程序共享,我们不希望 Tomcat 无意中选择用于其他应用程序的 JVM 选项。 I prefer to use CATALINA_OPTS.我更喜欢使用 CATALINA_OPTS。

How to set java heap size in JBoss?如何在 JBoss 中设置 Java 堆大小?

Stop JBoss server, edit $JBOSS_HOME/bin/run.conf, and then restart JBoss server.停止 JBoss 服务器,编辑 $JBOSS_HOME/bin/run.conf,然后重新启动 JBoss 服务器。 You can change the line with JAVA_OPTS to something like:您可以将带有 JAVA_OPTS 的行更改为:

JAVA_OPTS="-server -Xms128m -Xmx128m"

How to set java heap size in Eclipse?如何在 Eclipse 中设置 Java 堆大小? You have 2 options:您有 2 个选择:

  1. Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.将 eclipse-home/eclipse.ini 编辑为如下所示的内容并重新启动 Eclipse。

    -vmargs-Xms64m-Xmx256m -vmargs-Xms64m-Xmx256m

  2. Or, you can just run eclipse command with additional options at the very end.或者,您可以在最后运行带有附加选项的 eclipse 命令。 Anything after -vmargs will be treated as JVM options and passed directly to the JVM. -vmargs 之后的任何内容都将被视为 JVM 选项并直接传递给 JVM。 JVM options specified in the command line this way will always override those in eclipse.ini.以这种方式在命令行中指定的 JVM 选项将始终覆盖 eclipse.ini 中的选项。 For example,例如,

    eclipse -vmargs -Xms64m -Xmx256m日食-vmargs -Xms64m -Xmx256m

How to set java heap size in NetBeans?如何在 NetBeans 中设置 Java 堆大小?

Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf.退出 NetBeans,编辑文件 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?如何在 Apache Ant 中设置 java 堆大小?

Set environment variable ANT_OPTS.设置环境变量 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.查看文件$ANT_HOME/bin/ant%ANT_HOME%\\bin\\ant.bat ,了解 Ant 运行时如何使用此变量。

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

If you increase the virtual memory of your Tomcat server then it will be OK.如果您增加Tomcat服务器的虚拟内存,那么就可以了。

Steps:脚步:

  1. In NB go through the windows menu and add Services在 NB 中通过 windows 菜单并添加服务
  2. You will find Tomcat in the services.您将在服务中找到 Tomcat。 Right click on Tomcat server and select Properties右键单击Tomcat服务器并选择属性
  3. Go to the platform in the properties and write -Xms512m in VM options field转到属性中的平台并在 VM 选项字段中写入-Xms512m

I'm guessing that increasing the memory won't fix the problem.我猜增加内存不会解决问题。 What is that MonitorFilter doing? MonitorFilter 在做什么? 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.如果这是一个 Web 应用程序,请查看您是否可以关闭该过滤器并在没有它的情况下运行。 If you have success, you know that the MonitorFilter is causing your to fail.如果您成功了,您就知道 MonitorFilter 导致您失败。

This has nothing to do with NetBeans (well, perhaps), rather it has to do with Tomcat.这与 NetBeans 无关(好吧,也许),而与 Tomcat 有关。 Tomcat is the process that is running out of heap, not NetBeans. Tomcat 是耗尽堆的进程,而不是 NetBeans。 Track down the startup process for your Tomcat.跟踪 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.如果它与 NB 捆绑在一起,那么 Tomcat 被埋在 NB 安装中,检查“enterpriseN”目录,N 是一个数字,Tomcat 可能在那里,它是它的一个相当通用的发行版。

As to why the monitor is run OOM, that's hard to say, it's a pretty simple process when you think about it.至于为什么监视器运行OOM,这很难说,仔细想想这是一个非常简单的过程。 You can also try disabling HTTP monitoring to see if it's a problem with the Monitoring itself or something with your application.您还可以尝试禁用 HTTP 监控,看看是监控本身有问题还是您的应用程序有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM