ZingMXBeans offer more detailed insight into the Garbage Collector activity of Azul Zing than the standard JVM Platform MXBeans of java.lang.management.ManagementFactory. They are not needed for most applications, but some users want to extract as much detail as possible for special high performance environments and then they can be interesting. See Monitoring Azul Zing for usage examples.
To make your application runnable also on other JVMs than Azul Zing when you have code included which uses ZingMXBeans, please refer to the following example about how to achieve this. On other JVMs where the ZingMXBeans are not available your application will still be usable when using this code pattern.
ZingMXBeansExample.java:
import java.util.List;
import com.azul.zing.management.*; class ZingMXBeansExample { public static void main(String[] args) { String prop = System.getProperty("com.azul.zing.management.useZingMXBeans"); if (prop == null) { System.out.println("No ZingMXBeans available"); } else { if (prop.equalsIgnoreCase("true")) { System.out.println("ZingMXBeans enabled"); // monitoring example: Runtime rt = Runtime.getRuntime(); List<GarbageCollectorMXBean> gcMXBeanList = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean gcMXBean: gcMXBeanList) { String name = gcMXBean.getName(); double val = gcMXBean.getPercentageOfTimeCollectorIsRunning(); System.out.println("GC Time Percent " + name + ": " + val); } } } } }
To compile the example:
javac -cp /opt/zing/zing-jdk8/etc/extensions/mxbeans/agents/ZingJMM.jar:. ZingMXBeansExample.java
Output on Azul Zing with ZingMXBeans enabled:
$ /opt/zing/zing-jdk11/bin/java -XX:+UseZingMXBeans ZingMXBeansExample ZingMXBeans enabled GC Time Percent GPGC New: 0.0 GC Time Percent GPGC Old: 0.0
Output on Azul Zing without ZingMXBeans:
$ /opt/zing/zing-jdk11/bin/java ZingMXBeansExample No ZingMXBeans available
Output on OpenJDK / Zulu where ZingMXBeans are not available:
$ /usr/lib/jvm/zulu11/bin/java ZingMXBeansExample No ZingMXBeans available
Note: Since Azul Zing version 22.12.0.0, the new OpenJDK 17 metrics separating GC concurrent duration and GC pauses in different MXBean / JMX metrics are available on Java 8, 11, 17 and 21. Those are in many use cases a simpler and more standardized alternative to ZingMXBeans. Details: https://docs.azul.com/prime/release-notes#prime_stream_22_12_0_0
Add Comment
Comments
Please sign in to leave a comment.