“java.lang.OutOfMemoryError:无法创建新的本机线程”

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

我们在32k线程之后得到java.lang.OutOfMemoryError:无法在8GB RAM VM上创建新的本机线程(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

我们还试过操作系统堆栈大小(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:46:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:本机   线程   java   lang   OutOfMemoryError

发布评论

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

>www.elefans.com

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