“java.lang.OutOfMemoryError:无法创建新的本机线程” [英] "java.lang.OutOfMemoryError : unable to create new native Thread"

查看:107
本文介绍了“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:无法创建新的本机线程”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆