内存溢出

一 OutOfMemery

1.准备会溢出的代码打包成Jar放入服务器运行

public class outOfMemery {
    private  String test;
    public outOfMemery(String testvalue){
        this.test=testvalue;
    }

    public static void main(String[] args){

        List<outOfMemery> list=new ArrayList<outOfMemery>();
        int i=0;
        while (true){
            i++;
            outOfMemery out=new outOfMemery(String.valueOf(i));
            list.add(out);


        }

    }
}

2.在服务器中运行

java -Xms40m -Xmx70m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/temp -jar  artifactidName.jar 
内存溢出

后台运行日志

内存溢出

 

 

 

内存溢出

内存溢出

通过查看快照发现outofmemery这个类33%  另外两个也是33%,然后查看代码发现也在此类中

二:gc overhand limit exceeded

代码无问题的情况下,将最大占有内存做下修改。

三metaspace 内存溢出

参考:https://blog.****.net/zxs0564335/article/details/105456408

四unable create native space

其他:

out of swap space

Out of memory: Kill process等

https://blog.****.net/renfufei/article/details/78088553

参考来源:

https://segmentfault.com/a/1190000022779335