Memory problem: 'unable to create new native thread'


You see this stacktrace in jenkins.log:

Caused by: java.lang.OutOfMemoryError: unable to create new native thread
      at java.lang.Thread.start0(Native Method)
      at java.lang.Thread.start(
      at java.util.concurrent.ThreadPoolExecutor.addWorker(
      at java.util.concurrent.ThreadPoolExecutor.execute(



Great chances are you are hitting one of the following system OS limit:

  • number of running user processes
  • number of opened files

To see the current limits of your system, run ulimit -a on the command-line with the user running Jenkins (usually jenkins). You should see something like this:

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 30
file size               (blocks, -f) unlimited
pending signals                 (-i) 30654
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 99
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

To increase limits, add these lines to /etc/security/limits.conf:

jenkins      soft   nofile  4096
jenkins      hard   nofile  8192
jenkins      soft   nproc   30654        
jenkins      hard   nproc   30654

Note that this assumes jenkins is the Unix user running the Jenkins process.

You can now logout and login and check that the limits are correctly modified with ulimit -a (limits are applied when the Unix user logs in).

If it’s not, check that one PAM configuration file in /etc/pam.d/ contains this line:

session required

Have more questions?


  • 0
    Henrik Koren

    This was implemented waiting foe next restart

  • 0
    Fei Wang

    For Centos6 or Redhat6, nproc parameter should modify /etc/security/limits.d/90-nproc.conf rather than /etc/security/limits.conf

    Edited by Fei Wang
  • 0
    Thomas Hartwig

    Check for DefaultTasksMax in /etc/systemd/system.conf. It was introduced in newer Linux systems since 2016. It is 512 by default which is not much for multi threaded server systems.

  • 0
    Maxime Viargues

    We have this error happening but on a Windows machine. How to apply the same commands?

Please sign in to leave a comment.