本文整理匯總了Java中java.lang.management.ManagementFactory.getClassLoadingMXBean方法的典型用法代碼示例。如果您正苦於以下問題:Java ManagementFactory.getClassLoadingMXBean方法的具體用法?Java ManagementFactory.getClassLoadingMXBean怎麽用?Java ManagementFactory.getClassLoadingMXBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.ManagementFactory
的用法示例。
在下文中一共展示了ManagementFactory.getClassLoadingMXBean方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sense
import java.lang.management.ManagementFactory; //導入方法依賴的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);
}
示例2: bindTo
import java.lang.management.ManagementFactory; //導入方法依賴的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);
}
示例3: readClassLoadUsage
import java.lang.management.ManagementFactory; //導入方法依賴的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());
}
示例4: logParams
import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private String logParams() {
StringBuilder sb = new StringBuilder(500);
sb.append("Diagnostic information\n");
try {
RuntimeMXBean rmBean = ManagementFactory.getRuntimeMXBean();
CompilationMXBean cmpMBean = ManagementFactory.getCompilationMXBean();
// ThreadMXBean tmBean = ManagementFactory.getThreadMXBean();
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
ClassLoadingMXBean clMBean = ManagementFactory.getClassLoadingMXBean();
// MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// ObjectName hsDiag = new ObjectName("com.sun.management:name=HotSpotDiagnostic");
// com.sun.management.OperatingSystemMXBean sunOSMBean =
// ManagementFactory.getSunOperatingSystemMXBean();
// Map<String, String> props = new TreeMap<String, String>(rmBean.getSystemProperties());
// System.out.println("System properties");
// for (Map.Entry<String, String> entry: props.entrySet()) {
// System.out.println("Property: "+entry.getKey()+" Value: "+entry.getValue());
// }
sb.append("Input arguments:");
for (String s: rmBean.getInputArguments()) {
sb.append("\n\t").append(s);
}
if (cmpMBean != null) {
sb.append("\nCompiler: "+cmpMBean.getName()).append('\n');
}
// Memory
MemoryUsage usage = memoryBean.getHeapMemoryUsage();
logMemoryUsage(sb, usage, "Heap memory");
usage = memoryBean.getNonHeapMemoryUsage();
logMemoryUsage(sb, usage, "Non heap memory");
for (GarbageCollectorMXBean gcMBean: ManagementFactory.getGarbageCollectorMXBeans()) {
sb.append("Garbage collector: ").append(gcMBean.getName())
.append(" (Collections=").append(gcMBean.getCollectionCount())
.append(" Total time spent=").append(formatTime(gcMBean.getCollectionTime()))
.append(")\n");
}
// classes
int clsLoaded;
long clsTotal, clsUnloaded;
clsLoaded = clMBean.getLoadedClassCount();
clsTotal = clMBean.getTotalLoadedClassCount();
clsUnloaded = clMBean.getUnloadedClassCount();
sb.append("Classes: loaded=").append(clsLoaded)
.append(" total loaded=").append(clsTotal)
.append(" unloaded ").append(clsUnloaded).append('\n');
// } catch (MalformedObjectNameException ex) {
// Logger.getLogger("global").log(Level.WARNING, null, ex);
} catch (NullPointerException ex) {
LOG.log(Level.WARNING, null, ex);
}
return sb.toString();
}
示例5: initialize
import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
/** Should be called at earliest possible time */
public static void initialize() {
classLoadingBean = ManagementFactory.getClassLoadingMXBean();
}
示例6: setFactory
import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
private void setFactory() {
mxbean = ManagementFactory.getRuntimeMXBean();
// 以下是取得虛擬機的屬性
System.out.println("===============虛擬機信息===================");
System.out.println("虛擬機提供商:" + mxbean.getVmVendor());
System.out.println("虛擬機名稱:" + mxbean.getVmName());
System.out.println("當前類路徑:" + mxbean.getClassPath());
System.out.println("進程號@機器:" + mxbean.getName());
System.out.println("運行時間(毫秒):" + mxbean.getUptime());
// 類管理接口
System.out.println("===============類加載信息===================");
ClassLoadingMXBean aClassLoadingMXBean = ManagementFactory
.getClassLoadingMXBean();
System.out.println("已加載類總數:"
+ aClassLoadingMXBean.getLoadedClassCount());
System.out.println("Verbose狀態:" + aClassLoadingMXBean.isVerbose());
// 內存管理接口
System.out.println("===============內存信息=====================");
MemoryMXBean aMemoryMXBean = ManagementFactory.getMemoryMXBean();
System.out.println("終止被掛起數:"
+ aMemoryMXBean.getObjectPendingFinalizationCount());// 返回其終止被掛起的對象的近似數目
// 返回 Java 虛擬機使用的非堆內存的當前使用量
MemoryUsage aMemoryUsage = aMemoryMXBean.getNonHeapMemoryUsage(); // 虛擬機啟動時從係統得到的內存(以字節為單位)
System.out.println("虛擬機啟動時從係統得到的內存:" + aMemoryUsage.getInit()); // 表示當前已經使用的內存量(以字節為單位)
System.out.println("當前已經使用的內存量:" + aMemoryUsage.getUsed()); // 表示保證可以由
// Java
// 虛擬機使用的內存量(以字節為單位)
System.out.println("虛擬機使用的內存量:" + aMemoryUsage.getCommitted()); // 表示可以用於內存管理的最大內存量(以字節為單位)
System.out.println("內存管理的初始內存量:" + aMemoryUsage.getInit());
System.out.println("內存管理的最大內存量:" + aMemoryUsage.getMax());
System.out.println("總體描述:" + aMemoryUsage.toString());
java.util.List<GarbageCollectorMXBean> aGCMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollectorMXBean aGCMXBean = aGCMXBeans.get(0);
System.out.println("===============GC信息=====================");
System.out.println("收集總數:" + aGCMXBean.getCollectionCount());
System.out.println("收集時間:" + aGCMXBean.getCollectionTime());
System.out.println("內存管理器有效:" + aGCMXBean.isValid());
System.out.println("內存池名:" + aGCMXBean.getMemoryPoolNames()[0]);
System.out.println("內存池名:" + aGCMXBean.getMemoryPoolNames()[1]);
System.out.println("*****************End**********************");
}
示例7: getClassLoadingMXBean
import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
static ClassLoadingMXBean getClassLoadingMXBean() {
return ManagementFactory.getClassLoadingMXBean();
}
示例8: main
import java.lang.management.ManagementFactory; //導入方法依賴的package包/類
public static void main(String[] args) {
ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
System.out.println("Loaded classes: " + classLoadingMXBean.getLoadedClassCount());
System.out.println("Total loaded classes: " + classLoadingMXBean.getTotalLoadedClassCount());
System.out.println("Unloaded classes: " + classLoadingMXBean.getUnloadedClassCount());
}