Skip to content

Commit be2eca8

Browse files
committed
fix error
1 parent 64512e0 commit be2eca8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

class/src/main/java/jvm/oom/DirectMemoryOOM.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class DirectMemoryOOM {
2424

2525
private static final int mib = 1024 * 1024;
2626

27-
// 注意: -XX:MaxDirectMemorySize参数只对由DirectByteBuffer分配的内存有效,对Unsafe直接分配的内存无效
27+
// 注意: -XX:MaxDirectMemorySize参数只对由DirectByteBuffer分配的内存有效限制,对Unsafe直接分配的内存无效
2828

2929
/**
3030
* C语言malloc申请的也是虚拟内存,没有设置值的话操作系统不会分配物理内存
@@ -42,9 +42,10 @@ static void byUnsafe() throws IllegalAccessException, InterruptedException {
4242
while (true) {
4343
Thread.sleep(100);
4444
delta += 2;
45-
System.out.println("now " + delta);
45+
4646
// byte
4747
unsafe.allocateMemory(2 * mib);
48+
System.out.println("now " + delta);
4849
}
4950
}
5051

@@ -54,9 +55,9 @@ static void byBuffer() throws InterruptedException {
5455
while (true) {
5556
Thread.sleep(100);
5657
delta += 2;
57-
System.out.println("now " + delta);
5858
// byte
5959
ByteBuffer buf = ByteBuffer.allocateDirect(2 * mib);
60+
System.out.println("now " + delta);
6061
buf.putLong(2L);
6162
buf.flip();
6263
buffers.add(buf);

0 commit comments

Comments
 (0)