实践得出结论

小程序™:

/**
 * @author Chunming Liu
 */
public class HeapOOMTest {
    public static void main(String[] args) {
        new Thread ( () -> {
            ArrayList<byte[]> bytes = new ArrayList<> ();

            while (true) {
                System.out.println ( "[" + LocalDateTime.now () + "] " + Thread.currentThread () );
                bytes.add ( new byte[1024 * 1024] );
                try {
                    Thread.sleep ( 1000 );
                } catch (InterruptedException e) {
                    e.printStackTrace ();
                }
            }
        } ).start ();
        new Thread ( () -> {
            while (true) {
                System.out.println ( LocalDateTime.now () + "==" + Thread.currentThread () );
                try {
                    Thread.sleep ( 1000 );
                } catch (InterruptedException e) {
                    e.printStackTrace ();
                }
            }
        } ).start ();
    }
}

运行之前添加JVM参数

-Xms16m -Xmx32m

image-20210614071732239

通过运行期间发生了 OOM但是可以出程序还是在正常运行

image-20210614071838907

Jconsole监控堆信息

image-20210614072230423

JVM运行时内存情况

image-20210614073643362

结论

触发堆异常不会影响其他线的运行,通过VM的内存情况,可以看出第一次发生的GC会将堆信息移动到老年代,后面的GC伊甸区活动,猜测和GC的策略有关(当前的GC策略:ParScav:MSC)