最近碰着了java.lang.OutOfMemoryError: unable to create new native thread,籍由这个机会尝试深入理解这个问题。
原因是创建过多thread引出的问题,JVM此时无法再创建出更多的线程。
这里的解释还是比较靠谱的
引用
As you can see, the maximum number of threads I can create decreases as the heap size gets larger. This is because the JVM immediately reserves the address space specified for the maximum heap size - That's probably because it needs that memory to be contiguous
.
表象便是当JVM的heap size设置过大时,thread的创建数量便会减少。
这里找到了一个还算清晰的说明
引用
Maximum heap size depends on maximum address space per process.
Maximum heap space is always smaller than maximum address space per process, because the process also needs space for stack, libraries, and so on.
JVM的堆和进程所需的栈都会消耗进程地址空间(address space),而地址空间则取决于操作系统,Windows中
引用
所有 32 位应用程序都有 4 GB 的进程地址空间(32 位地址最多可以映射 4 GB 的内存)。对于 Microsoft Windows 操作系统,应用程序可以访问 2 GB 的进程地址空间,称为用户模式虚拟地址空间。应用程序拥有的所有线程都共享同一个用户模式虚拟地址空间。其余 2 GB 为操作系统保留(也称为内核模式地址空间)。
目前我的理解是,JVM申请的heap会占用相同大小的地址空间(address space)。在Windows 32位操作系统中,分配给每个程序的地址空间只有2GB(当然也有3GB的开关)。而每个不同的JVM的堆和其创建的进程栈都依赖于同一个进程地址空间,所以这也是
此消彼长的原因。
有方法可以提高创建线程的数量:
1.减少JVM的heap size;
2.减少单个线程栈的大小,在JVM启动中使用-Xss参数。目前JDK1.4中每个线程栈所大小是256K,1.5是1M.
唉,大学的操作系统课程荒废了,地址空间也有些拎不清了。
分享到:
相关推荐
问题分析:java.lang.OutOfMemoryError unable to create new native thread - ado1986 - CSDN1
内存不足OOM java.lang.OutOfMemoryError.
java.lang.OutOfMemoryError: Java heap space 解决方法
java.lang.OutOfMemoryError: PermGen space 解决方案
搜集整理关于java错误处理:java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space 资料整理
Caused by: java.lang.OutOfMemoryError: PermGen space解决方案, avax.servlet.ServletException: java.lang.OutOfMemoryError: PermGen space at org.apache.jasper.servlet.JspServlet.service(JspServlet.java...
jvm内存详解,理解 JVM 如何使用 Windows 和 Linux 上的本机内存
tomcat内存溢出总结 在生产环境中tomcat内存设置不好很容易出现内存溢出。造成内存原因是不一样的,当然处理方式也不一样。 这里根据平时遇到的情况和... 3.OutOfMemoryError: unable to create new native thread.
java.lang.OutOfMemoryError: PermGen space及其解决方法,解决项目太大tomcat内存溢出
解决OutOfMemoryError: PermGen space,过程是痛苦的,结果是舒畅的
NULL 博文链接:https://geyubin.iteye.com/blog/779330
java.lang.OutOfMemoryError: PermGen space
Tomcat给我的java.lang.OutOfMemoryError: PermGenTomcat给我的java.lang.OutOfMemoryError: PermGenTomcat给我的java.lang.OutOfMemoryError: PermGenTomcat给我的java.lang.OutOfMemoryError: PermGenTomcat给我的...
java虚拟机OutOfMemoryError:Java heap space堆dump文件,可以直接用来分析。
JBeret是。 它还包含在在Java EE环境中提供可移植批处理支持。...并可能在某些计算机上引起内存错误: OutOfMemoryError: unable to create new native thread增加ulimit以避免此类错误。 例如, uli
报错 java.lang.OutOfMemoryError: PermGen space 报错 java.lang.OutOfMemoryError: Java heap 启动报错java.lang.ClassNotFoundException: 1catalina.org.apache.juli.FileHandler JAVA_OPTS="-server -Xms800m ...
记录java.lang.OutOfMemoryError:Java heap space的情况 文章内容: 一.问题描述+原因分析+解决方案 二.JVM调优说明 三.Tomcat添加到jvisualvm监控
OutOfMemoryError的8种经典案例,Java heap space、GC overhead limit exceeded、Permgen space、Metaspace、Unable to create new native thread、Out of swap space?、Requested array size exceeds VM limit、...
tomcat内存溢出解决办法,错误信息:java.lang.OutOfMemoryError:PermGen space 参考该文档可快速解决内存溢出的问题,服务器:tomcat