“java.lang.OutOfMemoryError:无法创建新的本地线程";

编程入门 行业动态 更新时间:2024-10-23 07:15:49
本文介绍了“java.lang.OutOfMemoryError:无法创建新的本地线程";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们在 8GB RAM VM 上收到 java.lang.OutOfMemoryError : 无法创建新的本地线程" 32k 线程后 (ps -eLF| grep -c java)

We are getting "java.lang.OutOfMemoryError : unable to create new native Thread" on 8GB RAM VM after 32k threads (ps -eLF| grep -c java)

然而,"top" 和 "free -m" 显示 50% 可用内存.JDk 是 64 位的,并且在 HotSpot 和 JRockit 上都尝试过.Server 有 Linux 2.6.18

However, "top" and "free -m" shows 50% free memory available. JDk is 64 bit and tried with both HotSpot and JRockit.Server has Linux 2.6.18

我们还尝试了OS stack size (ulimit -s) 调整和最大进程(ulimit -u) 限制,limit.conf 增加但都是徒劳的.

We also tried OS stack size (ulimit -s) tweaking and max process(ulimit -u) limits, limit.conf increase but all in vain.

我们还尝试了几乎所有可能的堆大小组合,保持低、高等.

Also we tried almost all possible of heap size combinations, keeping it low, high etc.

我们用来运行应用程序的脚本是

The script we use to run application is

/opt/jrockit-jdk1.6/bin/java -Xms512m -Xmx512m -Xss128k -jar JavaNatSimulator.jar /opt/tools/jnatclients/natSimulator.properties

感谢回复.

我们已经尝试编辑/etc/security/limits.conf 和 ulimit 但还是一样

We have tried editing /etc/security/limits.conf and ulimit but still that same

[root@jboss02 ~]# ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 72192 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 65535 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 72192 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

推荐答案

这不是内存问题,尽管异常名称高度暗示如此,而是操作系统资源问题.您的本机线程即将用完,即操作系统允许您的 JVM 使用多少线程.

This is not a memory problem even though the exception name highly suggests so, but an operating system resource problem. You are running out of native threads, i.e. how many threads the operating system will allow your JVM to use.

这是一个不常见的问题,因为您很少需要那么多.你有很多无条件的线程在线程应该但没有完成的地方产生吗?

This is an uncommon problem, because you rarely need that many. Do you have a lot of unconditional thread spawning where the threads should but doesn't finish?

如果可能,您可能会考虑重写为在 Executor 的控制下使用 Callable/Runnables.有许多标准执行器具有各种行为,您的代码可以轻松控制.

You might consider rewriting into using Callable/Runnables under the control of an Executor if at all possible. There are plenty of standard executors with various behavior which your code can easily control.

(线程数受限的原因有很多,但因操作系统而异)

(There are many reasons why the number of threads is limited, but they vary from operating system to operating system)

更多推荐

“java.lang.OutOfMemoryError:无法创建新的本地线程";

本文发布于:2023-11-25 18:47:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   lang   java   quot   OutOfMemoryError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!