When I recently published an application on a Linux server, I encountered the following exception:
Caused by: java.lang.OutOfMemoryError: unable to create new native threadat java.lang.Thread.start0(Native Method)at java.lang.Thread.start(Thread.java:640)
At first glance, it may be thought that the system memory is insufficient. If you think about it like this, you will be taken to the channel with this prompt.
The essence of the above error message is that the Linux operating system cannot create more processes, resulting in errors. To solve this problem, you need to modify Linux to allow more processes to be created.
Modify the maximum number of processes in Linux
You can use ulimit-a to view system parameters of the current Linux system.
$ ulimit -acore file size (blocks, -c) 0data seg size (kbytes, -d) unlimitedscheduling priority (-e) 0file size (blocks, -f) unlimitedpending signals (-i) 62357max locked memory (kbytes, -l) 64max memory size (kbytes, -m) unlimitedopen files (-n) 65536pipe size (512 bytes, -p) 8POSIX message queues (bytes, -q) 819200real-time priority (-r) 0stack size (kbytes, -s) 10240cpu time (seconds, -t) unlimitedmax user processes (-u) 4096virtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited
Among the above parameters, we usually pay more attention to the maximum number of files that a process can open, that is, open files. The maximum number of processes allowed to be created is the max user processes parameter. We can use ulimit-u 4096 to modify the value of max user processes, but it only takes effect in the session of the current terminal. After logon, the default value is still used.
The correct modification method is to modify the value in the/etc/security/limits. d/90-nproc.conf file. Let's take a look at what this file contains:
$ cat /etc/security/limits.d/90-nproc.conf # Default limit for number of user's processes to prevent# accidental fork bombs.# See rhbz #432903 for reasoning.* soft nproc 4096
You only need to modify the value 4096 in the above file.
About the nproc restrictions of ulimit in RHEL6
Linux/Unix ulimit command details
Linux File System limits ulimit usage
Linux certification guide: Linux ulimit command
Linux host uses ulimit to improve system performance
Improve Linux system performance through ulimit