Due to a bug in the sigar library version I am using (returns bogus values for swap), I tried using com.sun.management.OperatingSystemMXBean
instead. This worked fine and gave me the desired results (on Windows).
Class<?> sunMxBeanClass = Class.forName("com.sun.management.OperatingSystemMXBean");
sunMxBeanInstance = sunMxBeanClass.cast(ManagementFactory.getOperatingSystemMXBean());
getFreeSwapSpaceSize = getMethodWithName(sunMxBeanClass, "getFreeSwapSpaceSize");
getTotalSwapSpaceSize = getMethodWithName(sunMxBeanClass, "getTotalSwapSpaceSize");
However this breaks with java 9. Is there another way to query swap file / partition information using java? I don't want to introduce a new library or version of sigar.
Cross platform solutions appreciated but windows is enough :--)
Thanks
java.management
andjdk.management
. Using the latter inevitably adds more dependencies to an application, but makescom.sun.management.OperatingSystemMXBean
directly available. Using the former requires dynamic discovery of these extensions. (Why they don’t just offer these properties in the base interface is above me; it’s not as if there weren’t already tons of optional properties…) – Factory