ZingMXBeans offer more detailed insight into the Garbage Collector activity of Azul Platform Prime 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 Platform Prime for usage examples.
To make your application runnable also on other JVMs than Azul Platform Prime 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 Platform Prime 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 Platform Prime 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
Add Comment
Comments
Please sign in to leave a comment.