有 Java 编程相关的问题?

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

java XX:OnAutofmemoryError=“kill 9%p”问题

我在尝试将-XX:OnOutOfMemoryError="kill -9 %p"命令传递到jvm参数时遇到问题

我正在使用Jetty7,并且在一开始就有了它。ini文件。启动时,请告诉我以下错误。这是jre/jre1的特点。6.0_03l64

Starting Jetty: STARTED Jetty Tue Apr 26 09:54:26 EDT 2011
Unrecognized option: -9
Could not create the Java virtual machine.

开始。ini文件如下所示

#===========================================================
# If the arguements in this file include JVM arguments
# (eg -Xmx512m) or JVM System properties (eg com.sun.???),
# then these will not take affect unless the --exec
# parameter is included or if the output from --dry-run
# is executed like:
#   eval $(java -jar start.jar --dry-run)
#
# Below are some recommended options for Sun's JRE
#-----------------------------------------------------------
  --exec
# -Dcom.sun.management.jmxremote
  -Xmx4096m
  -Xmn512m
  -DLABEL=PROD_APP
  -verbose:gc
  -Xloggc:/export/opt/prod_app/logs/gc.log
  -XX:OnOutOfMemoryError="kill -9 %p"
# -XX:+PrintGCDateStamps
  -XX:+PrintGCTimeStamps
  -XX:+PrintGCDetails
  -XX:+PrintTenuringDistribution
# -XX:+PrintCommandLineFlags
# -XX:+DisableExplicitGC
# -XX:+UseConcMarkSweepGC
# -XX:ParallelCMSThreads=2
# -XX:+CMSClassUnloadingEnabled
# -XX:+UseCMSCompactAtFullCollection
# -XX:CMSInitiatingOccupancyFraction=80

对排码头进行评论将不会产生任何问题。但是,由于系统内存泄漏,我们确实需要添加此参数,以防止进程崩溃时进一步损坏

有没有人知道我做错了什么,或者我如何解决这个问题


共 (6) 个答案

  1. # 2 楼答案

    你需要使用 -XX:OnOutOfMemoryError=/bin/kill -9 %p

    此外,如果您想测试更改,可以在终止消息之前回显消息

    -XX:OnOutOfMemoryError=/bin/date; /bin/echo custom message;/bin/kill -9 %p

  2. # 3 楼答案

    我最近遇到过这个问题。我通过将选项设置为JAVA_TOOL_OPTIONS环境变量解决了这个问题。这个变量是by Oracle记录的,您必须export在shell命令中使用这个变量,JVM将它附加到参数中

  3. # 4 楼答案

    我相信你需要引用整个选项,比如:

      "-XX:OnOutOfMemoryError=kill -9 %p"
    
  4. # 5 楼答案

    在Java版本8u92中,VM参数

    • -XX:+ExitOnOutOfMemoryError
    • -XX:+CrashOnOutOfMemoryError

    已添加,请参见release notes

    ExitOnOutOfMemoryError
    When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors.

    CrashOnOutOfMemoryError
    If this option is enabled, when an out-of-memory error occurs, the JVM crashes and produces text and binary crash files.

    增强请求:JDK-8138745(参数命名错误,尽管JDK-8154713ExitOnOutOfMemoryError而不是ExitOnOutOfMemory

  5. # 6 楼答案

    作为hadoop选项运行,我遇到了同样的问题。 答案是:

    -XX:OnOutOfMemoryError='kill -9 %p'
    

    以下是OOM上的stdout:

    #
    # java.lang.OutOfMemoryError: Java heap space
    # -XX:OnOutOfMemoryError="kill -9 %p"
    #   Executing /bin/sh -c "kill -9 11902"...
    

    我也试过:

    -XX:OnOutOfMemoryError='"kill -9 %p"'
    

    它开始了,但在它上面

    # java.lang.OutOfMemoryError: Java heap space
    # -XX:OnOutOfMemoryError="kill' '-9' '%p"
    #   Executing /bin/sh -c "kill' '-9' '1164"...
    

    但斯特尔: sh:kill-9 1164:未找到命令

    这些甚至不会开始:

    '-XX:OnOutOfMemoryError=kill -9 %p'
    "-XX:OnOutOfMemoryError=kill -9 %p"
    -XX:OnOutOfMemoryError="kill -9 %p"