本文整理汇总了Java中java.lang.management.ClassLoadingMXBean类的典型用法代码示例。如果您正苦于以下问题:Java ClassLoadingMXBean类的具体用法?Java ClassLoadingMXBean怎么用?Java ClassLoadingMXBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClassLoadingMXBean类属于java.lang.management包,在下文中一共展示了ClassLoadingMXBean类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instantiateClassLoaderMetrics
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
metrics.<Long, Gauge<Long>>gauge("ClassesLoaded", new Gauge<Long> () {
@Override
public Long getValue() {
return mxBean.getTotalLoadedClassCount();
}
});
metrics.<Long, Gauge<Long>>gauge("ClassesUnloaded", new Gauge<Long> () {
@Override
public Long getValue() {
return mxBean.getUnloadedClassCount();
}
});
}
示例2: doExecute
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
protected Object doExecute() throws Exception {
if (numThreads != null) {
numberOfDisplayedThreads = Integer.parseInt(numThreads);
}
if (updates != null) {
DEFAULT_REFRESH_INTERVAL = Integer.parseInt(updates);
}
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();
KTop(runtime, os, threads, mem, cl);
} catch (IOException e) {
//Ignore
}
return null;
}
示例3: main
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
ClassLoadingMXBean classMXBean = ManagementFactory
.getClassLoadingMXBean();
if (!classMXBean.isVerbose()) {
fail();
}
Class.forName(args[0]);
classMXBean.setVerbose(false);
if (classMXBean.isVerbose()) {
fail();
}
System.out.println(args[1]);
Class.forName(args[2]);
classMXBean.setVerbose(true);
if (!classMXBean.isVerbose()) {
fail();
}
System.out.println(args[3]);
System.exit(77);
}
示例4: addClassLoadingInfo
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
/**
* Creates the metadata for the {@link ClassLoadingMXBean}bean. For this
* type of platform bean the metadata covers :
* <ul>
* <li>4 attributes
* <li>0 constructors
* <li>0 operations
* <li>0 notifications
* </ul>
*
* @param result
*/
private static void addClassLoadingInfo(HashMap<String, MBeanInfo> result) {
// Attributes
MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[4];
attributes[0] = new MBeanAttributeInfo("LoadedClassCount", Integer.TYPE
.getName(), "LoadedClassCount", true, false, false);
attributes[1] = new MBeanAttributeInfo("TotalLoadedClassCount",
Long.TYPE.getName(), "TotalLoadedClassCount", true, false,
false);
attributes[2] = new MBeanAttributeInfo("UnloadedClassCount", Long.TYPE
.getName(), "UnloadedClassCount", true, false, false);
attributes[3] = new MBeanAttributeInfo("Verbose", Boolean.TYPE
.getName(), "Verbose", true, true, true);
result.put(ClassLoadingMXBean.class.getName(), new MBeanInfo(
ClassLoadingMXBeanImpl.class.getName(),
ClassLoadingMXBeanImpl.class.getName(), attributes, null, null,
null));
}
示例5: testNewPlatformMXBeanProxy_ClassLoadingMXBean
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
public void testNewPlatformMXBeanProxy_ClassLoadingMXBean()
throws Exception {
ClassLoadingMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
ManagementFactory.getPlatformMBeanServer(),
"java.lang:type=ClassLoading", ClassLoadingMXBean.class);
assertNotNull(proxy);
ClassLoadingMXBean classLoadingMXBean = ManagementFactory
.getClassLoadingMXBean();
assertEquals(proxy.getLoadedClassCount(), classLoadingMXBean
.getLoadedClassCount());
assertEquals(proxy.getTotalLoadedClassCount(), classLoadingMXBean
.getTotalLoadedClassCount());
assertEquals(proxy.getUnloadedClassCount(), classLoadingMXBean
.getUnloadedClassCount());
assertEquals(proxy.isVerbose(), classLoadingMXBean.isVerbose());
boolean initialVal = proxy.isVerbose();
proxy.setVerbose(!initialVal);
assertTrue(proxy.isVerbose() != initialVal);
proxy.setVerbose(initialVal);
assertEquals(initialVal, proxy.isVerbose());
}
示例6: testClassLoadingMXBean
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
@Test
public void testClassLoadingMXBean() throws IOException {
DescribedResource describedResource = basicResourceTest("class-loading", null);
ClassLoadingMXBean mbean = ManagementFactory.getClassLoadingMXBean();
boolean verbose = describedResource.resource.get("verbose").asBoolean();
Assert.assertEquals(mbean.isVerbose(), verbose);
ModelNode op = getOperation("write-attribute", "class-loading", null);
op.get("name").set("verbose");
op.get("value").set(!verbose);
executeOp(op, false);
Assert.assertEquals(mbean.isVerbose(), !verbose);
// Restore
mbean.setVerbose(verbose);
}
示例7: sense
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
@Override
public void sense(final MetricRecorder.Context metricContext)
{
ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();
metricContext.record(CURRENT_COUNT, mxBean.getLoadedClassCount(), Unit.NONE);
metricContext.record(TOTAL_COUNT, mxBean.getTotalLoadedClassCount(), Unit.NONE);
metricContext.record(UNLOADED_COUNT, mxBean.getUnloadedClassCount(), Unit.NONE);
}
示例8: bindTo
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
@Override
public void bindTo(MeterRegistry registry) {
ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
Gauge.builder("jvm.classes.loaded", classLoadingBean, ClassLoadingMXBean::getLoadedClassCount)
.tags(tags)
.description("The number of classes that are currently loaded in the Java virtual machine")
.register(registry);
FunctionCounter.builder("jvm.classes.unloaded", classLoadingBean, ClassLoadingMXBean::getUnloadedClassCount)
.tags(tags)
.description("The total number of classes unloaded since the Java virtual machine has started execution")
.register(registry);
}
示例9: doClassLoadingMXBeanTest
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
private final int doClassLoadingMXBeanTest(MBeanServerConnection mbsc) {
int errorCount = 0 ;
System.out.println("---- ClassLoadingMXBean") ;
try {
ObjectName classLoadingName =
new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME) ;
MBeanInfo mbInfo = mbsc.getMBeanInfo(classLoadingName);
errorCount += checkNonEmpty(mbInfo);
System.out.println("getMBeanInfo\t\t"
+ mbInfo);
ClassLoadingMXBean classLoading = null;
classLoading = JMX.newMXBeanProxy(mbsc,
classLoadingName,
ClassLoadingMXBean.class) ;
System.out.println("getLoadedClassCount\t\t"
+ classLoading.getLoadedClassCount());
System.out.println("getTotalLoadedClassCount\t\t"
+ classLoading.getTotalLoadedClassCount());
System.out.println("getUnloadedClassCount\t\t"
+ classLoading.getUnloadedClassCount());
System.out.println("isVerbose\t\t"
+ classLoading.isVerbose());
System.out.println("---- OK\n") ;
} catch (Exception e) {
Utils.printThrowable(e, true) ;
errorCount++ ;
System.out.println("---- ERROR\n") ;
}
return errorCount ;
}
示例10: readClassLoadUsage
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
private void readClassLoadUsage(MonitorElementInstance instance) {
ClassLoadingMXBean clmb = ManagementFactory.getClassLoadingMXBean();
instance.setValue("class_total", clmb.getTotalLoadedClassCount());
instance.setValue("class_load", clmb.getLoadedClassCount());
instance.setValue("class_unload", clmb.getUnloadedClassCount());
}
示例11: addClassLoadingMetrics
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
/**
* Add class loading metrics.
* @param result the result
*/
protected void addClassLoadingMetrics(Collection<Metric<?>> result) {
ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
result.add(new Metric<Long>("classes",
(long) classLoadingMxBean.getLoadedClassCount()));
result.add(new Metric<Long>("classes.loaded",
classLoadingMxBean.getTotalLoadedClassCount()));
result.add(new Metric<Long>("classes.unloaded",
classLoadingMxBean.getUnloadedClassCount()));
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:SystemPublicMetrics.java
示例12: displayManagementBean
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
private String displayManagementBean(ClassLoadingMXBean mxBean) {
StringBuilder sb = new StringBuilder();
if (mxBean != null) {
sb.append(mxBean.toString()).append('\n');
sb.append(mxBean.getObjectName().toString()).append('\n');
sb.append("Loaded Class Count:\t").append(mxBean.getLoadedClassCount()).append('\n');
sb.append("Total Loaded Class Count:\t").append(mxBean.getTotalLoadedClassCount()).append('\n');
sb.append("Unloaded Class Count:\t").append(mxBean.getUnloadedClassCount()).append('\n');
}
return sb.toString();
}
示例13: getClassLoadingMXBean
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
public synchronized ClassLoadingMXBean getClassLoadingMXBean() throws IOException {
if (hasPlatformMXBeans && classLoadingMBean == null) {
classLoadingMBean =
newPlatformMXBeanProxy(server, CLASS_LOADING_MXBEAN_NAME,
ClassLoadingMXBean.class);
}
return classLoadingMBean;
}
示例14: testClassLoadingMXBean
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
@Test
public void testClassLoadingMXBean() {
ClassLoadingMXBean classLoadingMXBean = ClassLoaderUtils.classLoadingMXBean;
Assert.assertEquals(classLoadingMXBean.getTotalLoadedClassCount(), ClassLoaderUtils.getTotalLoadedClassCount());
Assert.assertEquals(classLoadingMXBean.getLoadedClassCount(), ClassLoaderUtils.getLoadedClassCount());
Assert.assertEquals(classLoadingMXBean.getUnloadedClassCount(), ClassLoaderUtils.getUnloadedClassCount());
Assert.assertEquals(classLoadingMXBean.isVerbose(), ClassLoaderUtils.isVerbose());
ClassLoaderUtils.setVerbose(true);
Assert.assertTrue(ClassLoaderUtils.isVerbose());
}
示例15: onCommand
import java.lang.management.ClassLoadingMXBean; //导入依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!isAllowed(sender, command)) {
sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
return true;
}
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
//java info
sender.sendMessage(PRIMARY_COLOR + "Java VM: " + SECONDARY_COLOR + runtimeBean.getVmName());
sender.sendMessage(PRIMARY_COLOR + "Java Version: " + SECONDARY_COLOR + StandardSystemProperty.JAVA_VERSION.value());
sender.sendMessage(PRIMARY_COLOR + "Java Vendor: " + SECONDARY_COLOR
+ runtimeBean.getVmVendor() + ' ' + runtimeBean.getVmVersion());
//vm specification
sender.sendMessage(PRIMARY_COLOR + "Spec name: " + SECONDARY_COLOR + runtimeBean.getSpecName());
sender.sendMessage(PRIMARY_COLOR + "Spec Vendor: " + SECONDARY_COLOR + runtimeBean.getSpecVendor());
sender.sendMessage(PRIMARY_COLOR + "Spec Version: " + SECONDARY_COLOR + runtimeBean.getSpecVersion());
//class loading
ClassLoadingMXBean classBean = ManagementFactory.getClassLoadingMXBean();
sender.sendMessage(PRIMARY_COLOR + "Loaded Classes: " + SECONDARY_COLOR + classBean.getLoadedClassCount());
sender.sendMessage(PRIMARY_COLOR + "Total Loaded: " + SECONDARY_COLOR + classBean.getTotalLoadedClassCount());
sender.sendMessage(PRIMARY_COLOR + "Unloaded Classes: " + SECONDARY_COLOR + classBean.getUnloadedClassCount());
//garbage collector
List<GarbageCollectorMXBean> gcBean = ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean collector : gcBean) {
sender.sendMessage(PRIMARY_COLOR + "Garbage Collector: " + SECONDARY_COLOR + collector.getName());
sender.sendMessage(PRIMARY_COLOR + " Time: " + SECONDARY_COLOR + collector.getCollectionTime());
sender.sendMessage(PRIMARY_COLOR + " Count: " + SECONDARY_COLOR + collector.getCollectionCount());
}
return true;
}