java.lang.OutOfMemoryError: tomcat7 中的 Java 堆空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22292360/
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-13 14:46:26  来源:igfitidea点击:

java.lang.OutOfMemoryError: Java heap space in tomcat7

javatomcat7

提问by prabhu

I am getting this error in tomcat server.

我在 tomcat 服务器中收到此错误。

Exception in thread "http-bio-8080-exec-17" 
Exception in thread "http-bio-8080-exec-2"
Exception in thread "http-bio-8080-exec-15" 
Exception in thread "http-bio-8080-exec-20"
Exception in thread "http-bio-8080-exec-18" 
java.lang.OutOfMemoryError: Java heap space.

I have seen MAT but how do I generate the .hproffile in my Tomcat server.

我见过 MAT,但如何.hprof在我的 Tomcat 服务器中生成文件。

Thank you.

谢谢你。

回答by Taher Khorshidi

add this line to /path/to/tomcat/bin/setenv.sh(if doesn't exist create it) :

将此行添加到/path/to/tomcat/bin/setenv.sh(如果不存在则创建它):

CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m"

this increases tomcat's heap size to 1024MB.

这将 tomcat 的堆大小增加到 1024MB。

回答by ravi.patel

Solution as per your OS:

根据您的操作系统解决方案:

if Ubuntu:

如果Ubuntu

open .bashrc file available in user home folder (it is hidden) and Add or Edit one line among last 2-3 lines:

打开用户主文件夹中可用的 .bashrc 文件(它是隐藏的)并在最后 2-3 行中添加或编辑一行:

export CATALINA_OPTS="-Xms512m -Xmx1024m"

else Windows:

其他Windows

In your environment variables add/edit

在您的环境变量中添加/编辑

CATALINA_OPTS = "-Xms512m -Xmx1024m"

回答by Jobin

to remove the error edit the file

删除错误编辑文件

/etc/default/tomcat7   

replace with:

用。。。来代替:

JAVA_OPTS="-Djava.awt.headless=true -Xmx1280m -XX:+UseConcMarkSweepGC"

Then restart the web server.

然后重新启动 Web 服务器。

Xmxis the new maximum size of memory and it should be affordable by your machine.

Xmx是新的最大内存大小,您的机器应该可以负担得起。