JDK8 中 oom: unable to create new native thread 无法生成dump文件?

启动脚本如下
#!/bin/sh
nohup java -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=./ -XX:+PrintGCDetails -Xloggc:./gc.log -Dfile.encoding=utf-8 -jar demoOOM-0.0.1-SNAPSHOT.jar >> system.log 2>&1 &
echo $! > project.pid
tail -f system.log
按理说来应该是要在当前路径下,生成dump文件,但实际未生成,控制台打印结果如下
线程:10087
线程:10088
线程:10089
2022-11-11 09:49:30.165 ERROR 2435502 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: unable to create new native thread] with root cause

java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method) [na:1.8.0_312]
        at java.lang.Thread.start(Thread.java:717) [na:1.8.0_312]
        at com.example.demooom.TestController.createOOM(TestController.java:29) ~[classes!/:0.0.1-SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_312]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_312]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_312]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_312]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.23.jar!/:5.3.23]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.23.jar!/:5.3.23]
并未找到输出dump文件的提示,是否指定文件名也无效. 请问这个有可能是什么问题呢?
阅读 2.2k
1 个回答

不生成原因

有人提过这个 bug

The -XX:+HeapDumpOnOutOfMemoryError command-line option tells the HotSpot VM to generate a heap dump when an allocation from the Java heap or the permanent generation cannot be satisfied.

-XX:+HeapDumpOnOutOfMemoryError 含义是告诉 jvm,当无法满足来自堆或永久代的分配时的堆转储时,生成 dump 文件。

Allocation of a native thread is not from the heap or the permanent generation - hence failure to allocate one does not result in a heap dump. (There would be little point in dumping the heap as that is not what was exhausted.)

本机线程的分配不是来自堆或永久代, 因此分配失败不会导致堆转储。


为什么 jvm 不去生成

来自于另外一个论坛的相同 bug

There would be little point in dumping the heap as that is not what was exhausted.

他说生成堆存储没有什么意义,因为它并没有被用尽


能不能生成

最后,来自于一个问题 heapdumponoutofmemoryerror-not-creating-hprof

结论是,针对 unable to create new native thread 这样的错误,看起来没有可以自动生成的方法。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题