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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/717550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:41:57  来源:igfitidea点击:

java.lang.OutOfMemoryError: Java heap space with NetBeans

javatomcatnetbeansheapout-of-memory

提问by

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?

这是我在 NetBeans 启动的 Tomcat servlet 容器实例中运行 Web 应用程序时遇到的错误。为了解决这个问题,我什至在 netbeans.conf 中更改了堆大小,但它仍然显示相同的错误。我怎样才能避免这种情况发生?

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.

回答by Michael Myers

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). It should look something like this:

正确的方法是在项目上右击选择“属性”,然后选择“运行”;在那里您可以适当地设置 VM 选项(-Xmx256m例如)。它应该是这样的:

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

设置堆大小
(感谢VonC找到这张图片。)

回答by duffymo

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

我猜增加内存不会解决问题。MonitorFilter 在做什么?是什么吞噬了所有记忆?

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.

你最好的办法是弄清楚这一点。如果这是一个 Web 应用程序,请查看您是否可以关闭该过滤器并在没有它的情况下运行。如果您成功了,您就知道 MonitorFilter 导致您失败。

回答by Will Hartung

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.

这与 NetBeans 无关(好吧,也许),而与 Tomcat 有关。Tomcat 是耗尽堆的进程,而不是 NetBeans。跟踪 Tomcat 的启动过程。如果它与 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. You can also try disabling HTTP monitoring to see if it's a problem with the Monitoring itself or something with your application.

至于为什么监视器运行OOM,这很难说,仔细想想这是一个非常简单的过程。您还可以尝试禁用 HTTP 监控,看看是监控本身有问题还是您的应用程序有问题。

回答by Will Hartung

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
  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 -Xms512min VM options field
  1. 在 NB 中通过 windows 菜单并添加服务
  2. 您将在服务中找到 Tomcat。右键单击Tomcat服务器并选择属性
  3. 转到属性中的平台并-Xms512m在 VM 选项字段中写入

回答by Rakesh

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

停止Tomcat服务器,设置环境变量CATALINA_OPTS,然后重启Tomcat。查看文件tomcat-install/bin/catalina.shcatalina.bat了解如何使用此变量。例如,

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

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

catalina.bat或 中catallina.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 (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.

CATALINA_OPTS 名称专用于 Tomcat servlet 容器,而 JAVA_OPTS 可能被其他 Java 应用程序(例如,JBoss)使用。由于环境变量由所有应用程序共享,我们不希望 Tomcat 无意中选择用于其他应用程序的 JVM 选项。我更喜欢使用 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. You can change the line with JAVA_OPTS to something like:

停止 JBoss 服务器,编辑 $JBOSS_HOME/bin/run.conf,然后重新启动 JBoss 服务器。您可以使用 JAVA_OPTS 将行更改为:

JAVA_OPTS="-server -Xms128m -Xmx128m"

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

如何在 Eclipse 中设置 Java 堆大小?您有 2 个选择:

  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

  1. 将 eclipse-home/eclipse.ini 编辑为如下所示的内容并重新启动 Eclipse。

    -vmargs-Xms64m-Xmx256m

  2. 或者,您可以在最后运行带有附加选项的 eclipse 命令。-vmargs 之后的任何内容都将被视为 JVM 选项并直接传递给 JVM。以这种方式在命令行中指定的 JVM 选项将始终覆盖 eclipse.ini 中的选项。例如,

    日食-vmargs -Xms64m -Xmx256m

How to set java heap size in NetBeans?

如何在 NetBeans 中设置 Java 堆大小?

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

退出 NetBeans,编辑文件 netbeans-install/etc/netbeans.conf。例如,

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. Look at the file $ANT_HOME/bin/antor %ANT_HOME%\bin\ant.bat, for how this variable is used by Ant runtime.

设置环境变量 ANT_OPTS。查看文件$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)