问题描述
我无法在具有15G内存的Linux机器中创建超过32k的Java线程。
I cannot create more than 32k Java threads in Linux machine with 15G memory.
推荐答案
您可以使用以查找当前线程限制。
You can use a sample program to find out the current threads limit.
如果遇到线程main中的异常java.lang.OutOfMemoryError:无法创建新的本机线程
,请检查以下内容:
If you encounter Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
, check these:
-
在小型内存机器中
In small memory machines
每个Java线程都使用自己的堆栈内存。默认堆栈大小为1024k(= 1M)。您可以减小堆栈大小,如 java -Xss512k ...
。如果堆栈大小太小,则无法启动JVM。
Every Java thread consume its own stack memory. Default stack size is 1024k (= 1M). You can reduce the stack size like java -Xss512k ...
. JVM cannot be started if the stack size is too low.
并注意堆内存配置:(初始) -Xms
和(最大) -Xmx
。分配给堆的内存越多,堆栈的可用内存就越少。
And beware heap memory configurations: (initial) -Xms
and (maximum) -Xmx
. The more memory is allocated to heap, the less available memory for stack.
系统限制
ulimit -a
中的某些值会影响线程限制。
Some values in ulimit -a
can affect a thread limit.
-
最大内存大小
- 大多数64位计算机无限制 -
最大用户进程
- linux处理线程喜欢进程 -
虚拟内存
- 在大多数64位计算机上无限制。虚拟内存使用量增加-Xss配置(默认1024k)
max memory size
- unlimited on most 64bit machinesmax user processes
- linux treats threads like processesvirtual memory
- unlimited on most 64bit machines. virtual memory usage is increased by -Xss configuration (default 1024k)
您可以通过(临时)运行<$ c $更改这些值c> ulimit 命令或(永久)编辑 /etc/security/limits.conf
。
You can change these values by (temporal) running ulimit
command or (permanent) editing /etc/security/limits.conf
.
sys.kernel.threads-max
此值为系统全局(包括非JVM进程)最大线程数。检查 cat / proc / sys / kernel / threads-max
,并在必要时增加。
This value is the system-global (including non-JVM processes) maximum number of threads. Check cat /proc/sys/kernel/threads-max
, and increase if necessary.
echo 999999> / proc / sys / kernel / threads-max
或
sys.kernel.threads-max = 999999
在 /etc/sysctl.conf
中永久更改。
sys.kernel.pid_max
如果 cat / proc / sys / kernel / pid_max
与当前限制类似,请增加此值。 Linux将线程视为进程。
If cat /proc/sys/kernel/pid_max
is similar to current limit, increase this. Linux treats threads like processes.
echo 999999> / proc / sys / kernel / pid_max
或
sys.kernel.pid_max = 999999
在 /etc/sysctl.conf
中永久更改。
您可能需要增加 sys.vm.max_map_count
。
sys.vm.max_map_count
cat / proc / sys / vm / max_map_count
应至少为(2 x线程数) 。
cat /proc/sys/vm/max_map_count
should be at least (2 x thread-count).
尝试保护堆栈保护页失败。
和 OpenJDK 64位服务器VM警告:尝试释放堆栈保护页失败。
错误消息由JavaThread :: create_stack_guard_pages()发出,并调用os :: guard_memory()。在Linux中,此函数是mprotect()。
Attempt to protect stack guard pages failed.
and OpenJDK 64-Bit Server VM warning: Attempt to deallocate stack guard pages failed.
error messages are emitted by JavaThread::create_stack_guard_pages(), and it calls os::guard_memory(). In Linux, this function is mprotect().
echo 1999999> / proc / sys / vm / max_map_count
或
sys.vm.max_map_count = 1999999
在 /etc/sysctl.conf
中永久更改。
这篇关于如何增加JVM线程的最大数量(Linux 64位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!