Java Startup command optimization

Source: Internet
Author: User

Java-xms256m-xmx1024m-xss256k-jar Doors.jar > Doorlog.txt 2>&1 &

Problem description

The Java program throws the java.lang.OutOfMemoryError:unable to create new native thread as follows:

[Java]View PlainCopy
  1. Java.lang.OutOfMemoryError:unable to create new native thread
  2. At Java.lang.Thread.start0 (Native Method)
  3. At Java.lang.Thread.start (Thread.java:691)
  4. At Java.util.concurrent.ThreadPoolExecutor.addWorker (Threadpoolexecutor.java:949)
  5. At Java.util.concurrent.ThreadPoolExecutor.processWorkerExit (Threadpoolexecutor.java:1017)
  6. At Java.util.concurrent.ThreadPoolExecutor.runWorker (Threadpoolexecutor.java:1163)
  7. At Java.util.concurrent.threadpoolexecutor$worker.run (Threadpoolexecutor.java:615)
  8. At Java.lang.Thread.run (Thread.java:722)

[Java]View PlainCopy
    1. caused By:java.lang.OutOfMemoryError
    2. At Java.util.zip.ZipFile.open (Native Method)
    3. At Java.util.zip.zipfile.<init> (Zipfile.java:214)
    4. At Java.util.zip.zipfile.<init> (Zipfile.java:144)
    5. At Java.util.jar.jarfile.<init> (Jarfile.java:153)
    6. At Java.util.jar.jarfile.<init> (Jarfile.java:117)

From the JVM level to solve

Reduce the size of the thread stack

The JVM default thread stack size is 1024, so that when threads cause native virtual memory to be exhausted, it is actually sufficient when the size of the thread stack is 128K or 256K, so if we explicitly specify thread Stack is 128K or 256K, specific use-Xss,例如在JVM启动的JVM_OPT中添加如下配置

[Java]View PlainCopy
    1. -xss128k

Reduce the size of the initial allocation of the heap or PermGen

If the JVM starts with the following configuration in the Jvm_opt

[Java]View PlainCopy
    1. -xms1303m-xmx1303m-xx:permsize=256m-xx:maxpermsize=256m

We can delete or reduce the configuration of the initialization minimum value, as follows

[Java]View PlainCopy
    1. -xms256m-xmx1303m-xx:permsize=64m-xx:maxpermsize=256m

[Java]View PlainCopy
    1. -xmx1303m-xx:maxpermsize=256m

升级JVM到最新的版本

The latest version of the JVM generally does better in memory optimization, and upgrading the JVM to the latest version may alleviate the problem of testing

从操作系统层面去解决 使用64位操作系统

如果使用32位操作系统遇到unable to create new native thread,建议使用64位操作系统

Increase the OS's limit on threads

Set Nofile and Nproc in the Linux operating system, specific edits/etc/security/limits.conf添加如下:

[HTML]View PlainCopy
    1. Soft Nofile 2048
    2. Hard Nofile 8192

[HTML]View PlainCopy
    1. Soft Nproc 2048
    2. Hard Nproc 8192


If you are using red Hat Enterprise Linux 6, edit/etc/security/limits.d/90-nproc.conf,添加如下配置:

[HTML]View PlainCopy
      1. # cat/etc/security/limits.d/90-nproc.conf
      2. * Soft Nproc 1024
      3. Root Soft Nproc Unlimited
      4. User-nproc 2048

Java Startup command optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.