Created
May 28, 2025 13:20
-
-
Save rk-kmr/be4322b72a14ae04aeefc0260c01acf6 to your computer and use it in GitHub Desktop.
DirectByteBufferSafePoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.ByteBuffer; | |
import java.lang.management.ManagementFactory; | |
import java.lang.management.ThreadMXBean; | |
//java -Xlog:safepoint+stats -XX:+SafepointTimeout -Xmx10g DirectByteBufferSafePoint.java | |
public class DirectByteBufferSafePoint { | |
public static void main(String[] args) { | |
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); | |
new Thread() { | |
@Override | |
public void run() { | |
while (true) { | |
// ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024); // 1 MB -> 2 ms | |
// ByteBuffer buffer = ByteBuffer.allocateDirect(10* 1024 * 1024); // 10 MB -> 18 ms | |
ByteBuffer buffer = ByteBuffer.allocateDirect(Integer.MAX_VALUE); // 1 MB -> 18 ms | |
buffer.asCharBuffer(); | |
} | |
} | |
}.start(); | |
while (true) { | |
try { | |
threadMXBean.dumpAllThreads(false, false); | |
Thread.sleep(10); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment