oom

1、Java.lang.StackOverflowError
2、Java.lang.OutOfMemoryError:Java heap space
3、Java.lang.OutOfMemeoryError:GC overhead limit exceeded


-XX:+PrintGCDetails -Xms10m -Xmx10m
/**
 * gc回收时间过长会抛出OutOfMemoryError,过长指的是超过98%的时间用来做GC,并且回收不到2%的堆内存
 * 连续多次gc都只回收不到2%的极端情况下才会抛出
 * 假如不抛出 那么gc清理的这么点内存很快会再次填满,迫使gc再次执行,这样就形成了恶性循环
 * gc使用率一直是100%,而gc却没有任何成果
 */
public class GcOverheadDemo {
    public static void main(String[] args) {
        int i =0;
        List<String> list = new ArrayList<>();
        try {
            while (true){
                list.add(String.valueOf(++i).intern());
            }
        }catch (Throwable e){
            System.out.println("****"+i);
            e.printStackTrace();
            throw e;
        }
    }
}

[Full GC (Ergonomics) [PSYoungGen: 2047K->2047K(2560K)] [ParOldGen: 7151K->7151K(7168K)] 9199K->9199K(9728K), [Metaspace: 3592K->3592K(1056768K)], 0.0487609 secs] [Times: user=0.08 sys=0.00, real=0.05 secs] 
的是超过98%的时间用来做GC,并且回收不到2%的堆内存  

4、Java.lang.OutOfMemeoryError:Direct buffer memory
在这里插入图片描述

-XX:+PrintGCDetails -Xms10m -Xmx10m -XX:MaxDirectMemorySize=5m
public class DirectBufferMemoryDemo {
    public static void main(String[] args) throws InterruptedException {
        System.out.println("配置的 maxdirectbuffer:" + (sun.misc.VM.maxDirectMemory()/(double)1024/1024) +"MB");
        Thread.sleep(3000);
        ByteBuffer allocate = ByteBuffer.allocateDirect(6 * 1024 * 1024);
    }
}


[GC (Allocation Failure) [PSYoungGen: 2048K->496K(2560K)] 2048K->756K(9728K), 0.0015088 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
配置的 maxdirectbuffer:5.0MB
[GC (System.gc()) [PSYoungGen: 1590K->480K(2560K)] 1850K->1148K(9728K), 0.0025095 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 480K->0K(2560K)] [ParOldGen: 668K->1046K(7168K)] 1148K->1046K(9728K), [Metaspace: 3976K->3976K(1056768K)], 0.0133685 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 
Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
	at java.nio.Bits.reserveMemory(Bits.java:694)
	at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:123)
	at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:311)
	at cn.itcast.rpc.jvm.DirectBufferMemoryDemo.main(DirectBufferMemoryDemo.java:13)
Heap
 PSYoungGen      total 2560K, used 80K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 3% used [0x00000000ffd00000,0x00000000ffd14038,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
 ParOldGen       total 7168K, used 1046K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 14% used [0x00000000ff600000,0x00000000ff705a00,0x00000000ffd00000)
 Metaspace       used 4007K, capacity 4568K, committed 4864K, reserved 1056768K
  class space    used 442K, capacity 460K, committed 512K, reserved 1048576K

5、Java.lang.OutOfMemeoryError:unable to create new native thread
在这里插入图片描述
6、Java.lang.OutOfMemeoryError:Metaspace
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值