admin@glassfish.java.net

trying to use method.invoke() on MXBean

From: Jennifer Chou <Jennifer.Chou_at_Sun.COM>
Date: Thu, 04 Sep 2008 19:17:55 -0400

Hi,

I'm trying use method.invoke(..) on the MXBeans but I'm getting
IllegalAccessException on some but not all the MXBeans. Anybody know
why? And how to get around this problem?

java.lang.management.ClassLoadingMXBean clBean =
ManagementFactory.getClassLoadingMXBean();
java.lang.reflect.Method method =
clBean.getClass().getMethod("getLoadedClassCount", (Class[]) null);
method.invoke(clBean, (Object[]) null);

These get IllegalAccessException:
ClassLoadingMXBean
CompilationMXBean
GarbageCollectorMXBean
MemoryMXBean
MemoryMXBean

These allow me to use method.invoke():
OperatingSystemMXBean
MemoryUsage

Jennifer