王ks
王ks

Reputation: 35

why my code cause OOM and make JVM exit but i hava not see the JVM crash log (hs_err_pid)

i expect the code make JVM exit and crash ,and i see the JVM exit ,but i hava not see the JVM crash log (hs_err_pid) ,and the command " sudo egrep -i 'java' /var/log/messages" hava nothing message so its not the linux kill the process . but i can see that message "Process finished with exit code 1"so the question is what make jvm exit

start with : java -Xmx50M -Xms50M -XX:ErrorFile=/home/wks/javacode/java_error.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:/home/wks/javacode/gc.log

import java.util.ArrayList;
import java.util.List;



public class MakeVmAbort {

    static List<Thread> ts = new ArrayList<>();

    static List<byte[]> bs = new ArrayList<>();

    public static void main(String[] args) {

        try {
            while (true) {
                Thread t = new Thread(() -> {
                    while (true) {
                        bs.add(new byte[1024 * 1024]);
                        try {
                            Thread.sleep(500L);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                });
                t.start();
                ts.add(t);
            }

        } catch (Exception e) {
            System.out.println(e.getStackTrace());
        }
    }

}

Upvotes: 0

Views: 212

Answers (1)

王ks
王ks

Reputation: 35

the JVM exit because main Thread Throw OOM,so the JVM exit when the last non-daemon Thread finishes , thanks for @apangin

Upvotes: 0

Related Questions