java.lang.OutOfMemoryError: unable to create new native thread

前端 未结 3 1517
臣服心动
臣服心动 2020-12-09 22:46

i saw comment like this

one place i have seen this problem is if you keep creating threads, and instead of calling start(), call run() directly on the

3条回答
  •  一生所求
    2020-12-09 23:43

    This link describes quite nicely how this error is thrown by the JVM: http://javaeesupportpatterns.blogspot.ro/2012/09/outofmemoryerror-unable-to-create-new.html

    Basically it's very dependent on the OS. On RedHat Linux 6.5 (most likely other distros/version and kernel versions) the max_threads=max_process x 2.

    The max number of threads is very dependent on the number of allowed processes. Which the max number of processes is dependent on the max physical memory you have installed.

    If you have a look in the limits.conf file (on my RHL 6.5 it's in /etc/security/limits.d/90-nproc.conf). Exert form the file:

    # Default limit for number of user's processes to prevent
    # accidental fork bombs.
    # See rhbz #432903 for reasoning.
    
    *          soft    nproc     **1024**
    root       soft    nproc     unlimited
    

    You'll see that for non root users it's 1024 (which means 2048 max threads).

    To see the max number of threads that your user is allowed to create run this command "cat /proc/sys/kernel/threads-max" or "sysctl kernel.threads-max".

    To solve an issue like this (at least it worked for me) as root you'll need to ncrease the max allowed threads:

    echo 10000 > /proc/sys/kernel/threads-max

    This affects all users and the root. The user needs to log out and then log in again for the settings to take affect.

提交回复
热议问题