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

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

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