有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Tomcat7:执行关机时发生内存不足错误。嘘

我的Tomcat服务器已经运行了几天,但我无法正常关闭它,因为在执行shutdown.sh时,我遇到了以下错误:

# root@iZ94hjppdqzZ:~/projects/taolijie# cat hs_err_pid5519.log 
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2673), pid=5519, tid=3061726064
#
# JRE version:  (8.0_45-b14) (build )
# Java VM: Java HotSpot(TM) Server VM (25.45-b02 mixed mode linux-x86 )
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#

因此,我必须杀死Tomcat才能关闭它。但奇怪的是,Tomcat在生成此错误时工作正常(它可以正常处理web请求)

以下是虚拟机选项:

-server -Xms1G -Xmx1G -XX:+UseG1GC

我的服务器有2GB内存。有人知道发生了什么吗? 谢谢


共 (1) 个答案

  1. # 1 楼答案

    这似乎是通过以下方式设置内存配置:

    JAVA_OPTS="-server -Xms1G -Xmx1G -XX:+UseG1GC"
    

    JAVA_OPTS环境变量用于Tomcat的所有java进程,例如用于发送关闭消息的进程

    您需要通过设置来确定您正在配置Tomcat内存:

    CATALINA_OPTS="-server -Xms1G -Xmx1G -XX:+UseG1GC"
    

    然后,该设置将仅应用于Tomcat进程。使用默认内存设置,其他控制过程将正常执行