I am aware that you can use the -verbosegc to print information about the GC to the sysout but I don't want that. I want to intercept whenever GC triggers and print information about it to my custom logger, perhaps save last GC timestamp on a internal variable, etc.
Any hope here?
You can't hook the GC logging mechanism from within a Java program because when the GC thread(s) run the JVM is effectively stopped. Doing so would cause a deadlock so its a good thing we can't. Even using a custom launcher to try and hook via some handle reopen technique and calling up to Java would deadlock. Maybe if a reopen from within a custom launcher was possible (I don't know one way or the other) buffering the data and jumping from Java to native via JNI to retrieve the buffer might work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With