How to increase maximum number of JVM threads (Linux 64bit)

后端 未结 3 440
自闭症患者
自闭症患者 2020-12-04 17:17

I cannot create more than 32k Java threads in Linux machine with 15G memory.

3条回答
  •  再見小時候
    2020-12-04 17:29

    I ran into a similar problem in a Python program and the following worked for me. This is based on maczniak's answer above and https://superuser.com/questions/1219960/cannot-edit-proc-sys-kernel-threads-max.

    echo kernel.threads-max = 1073741823 >> /etc/sysctl.conf && echo 1073741823 > /proc/sys/kernel/threads-max
    echo kernel.pid_max = 999999 >> /etc/sysctl.conf && echo 999999 > /proc/sys/kernel/pid_max
    echo vm.max_map_count = 2147483646 >> /etc/sysctl.conf && echo 2147483646 > /proc/sys/vm/max_map_count
    echo vm.overcommit_memory = 1 >> /etc/sysctl.conf && echo 1 > /proc/sys/vm/overcommit_memory
    echo fs.inotify.max_user_instances = 256 >> /etc/sysctl.conf && echo 256 > /proc/sys/fs/inotify/max_user_instances
    sysctl -p
    

    I also had to set DefaultTasksMax in /etc/systemd/system.conf (or /etc/systemd/user.conf for user-run services) to DefaultTasksMax=unlimited.

    Systemd also applies a limit for programs run from a login-shell. These default to 4096 per user (will be increased to 12288) and are configured as UserTasksMax in the [Login] section of /etc/systemd/logind.conf.

    That is from this StackExchange question. Setting my UserTasksMax to UserTasksMax=999999 worked for me.

提交回复
热议问题