当前位置: 首页>>代码示例>>Java>>正文


Java ManagementFactory.newPlatformMXBeanProxy方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.newPlatformMXBeanProxy方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.newPlatformMXBeanProxy方法的具体用法?Java ManagementFactory.newPlatformMXBeanProxy怎么用?Java ManagementFactory.newPlatformMXBeanProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.newPlatformMXBeanProxy方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dumpHeap

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void dumpHeap(File file, boolean live)
{
    try
    {
        if (file.getParentFile() != null)
        {
            file.getParentFile().mkdirs();
        }
        Class clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        Object hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", clazz);
        Method m = clazz.getMethod("dumpHeap", String.class, boolean.class);
        m.invoke(hotspotMBean, file.getPath(), live);
    }
    catch (Throwable t)
    {
        logSevere("Could not write heap to {0}", file);
    }
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:20,代码来源:CauldronHooks.java

示例2: initHotspotMBean

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static void initHotspotMBean() {
    if(hotspotMBean == null) {
        synchronized(DumpUtils.class) {
            if(hotspotMBean == null) {
                try {
                    Class<?> clazz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");
                    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
                    hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(server, "com.sun.management:type=HotSpotDiagnostic", clazz);
                } catch(RuntimeException re) {
                    throw re;
                } catch(Exception exp) {
                    throw new RuntimeException(exp);
                }
            }
        }
    }
}
 
开发者ID:natanbc,项目名称:GabrielBot,代码行数:18,代码来源:DumpUtils.java

示例3: dumpHeap

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@CheckForNull
private static File dumpHeap(@NonNull final String path) {
    try {
        if (heapDumper == null) {
            final Class<?> clz = Class.forName("com.sun.management.HotSpotDiagnosticMXBean");   //NOI18N
            final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            final Object bean = ManagementFactory.newPlatformMXBeanProxy(
                server,
                "com.sun.management:type=HotSpotDiagnostic",    //NOI18N
                clz);
            final Method m = clz.getDeclaredMethod("dumpHeap", String.class, Boolean.TYPE);
            heapDumper = Pair.of(bean,m);
        }
        final File folder = new File(path);
        final File[] children = folder.listFiles();
        if (children != null) {
            final String namePattern = "heapdump_"; //NOI18N
            final Set<String> names = Arrays.stream(children)
                    .map((f) -> f.getName())
                    .filter((n) -> n.startsWith(namePattern))
                    .collect(Collectors.toSet());
            int index = 1;
            while (true) {
                if (!names.contains(namePattern + index)) {
                    break;
                }
                index++;
            }
            final File file = new File(folder, namePattern + index);
            heapDumper.second().invoke(heapDumper.first(), file.getAbsolutePath(), true);
            return file;
        }
    } catch (Exception e) {
        //pass
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:JavaCustomIndexer.java

示例4: getJVMUsage

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public Long getJVMUsage() {
    MemoryMXBean memBean = null;
    try {
        memBean = ManagementFactory.newPlatformMXBeanProxy
                (mbsconnector, ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
        MemoryUsage heap = memBean.getHeapMemoryUsage();
        return heap.getUsed();
    } catch (IOException e) {
        logger.error("", e);
        return 0L;
    }
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:13,代码来源:JMXClient.java

示例5: checkPidMatches

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * Ensures that the other process identifies itself by the same pid used by this stopper to
 * connect to that process. NOT USED EXCEPT IN TEST.
 * 
 * @return true if the pid matches
 * 
 * @throws IllegalStateException if the other process identifies itself by a different pid
 * @throws IOException if a communication problem occurred when accessing the
 *         MBeanServerConnection
 * @throws PidUnavailableException if parsing the pid from the RuntimeMXBean name fails
 */
boolean checkPidMatches() throws IllegalStateException, IOException, PidUnavailableException {
  final RuntimeMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(this.server,
      ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
  final int remotePid = ProcessUtils.identifyPid(proxy.getName());
  if (remotePid != this.pid) {
    throw new IllegalStateException(
        "Process has different pid '" + remotePid + "' than expected pid '" + this.pid + "'");
  } else {
    return true;
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:23,代码来源:LocalProcessController.java

示例6: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkDiagnosticOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkDiagnosticOptions(mbean);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:GetDiagnosticOptions.java

示例7: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    checkVMOption(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    checkVMOption(mbean);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:GetVMOption.java

示例8: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    List<HotSpotDiagnosticMXBean> list =
        ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
    HotSpotDiagnosticMXBean mbean = list.get(0);
    setAllVMOptions(mbean);

    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
                HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
                HotSpotDiagnosticMXBean.class);
    setAllVMOptions(mbean);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:SetAllVMOptions.java

示例9: main

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Random rand = new Random();

    // allocate a few direct buffers
    int bufferCount = 5 + rand.nextInt(20);
    buffers = new ArrayList<ByteBuffer>(bufferCount);
    long totalCapacity = 0L;
    for (int i=0; i<bufferCount; i++) {
        int cap = 1024 + rand.nextInt(4096);
        buffers.add( ByteBuffer.allocateDirect(cap) );
        totalCapacity += cap;
    }

    // create a mapped buffer
    Path tmpfile = Files.createTempFile("blah", null);
    tmpfile.toFile().deleteOnExit();
    try (FileChannel fc = FileChannel.open(tmpfile, READ, WRITE)) {
        mbb = fc.map(FileChannel.MapMode.READ_WRITE, 10, 100);
        bufferCount++;
        totalCapacity += mbb.capacity();
    }

    // use platform MXBeans directly
    List<BufferPoolMXBean> pools =
        ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
    check(pools, bufferCount, totalCapacity);

    // use MBeanServer
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> mbeans = server.queryNames(
        new ObjectName("java.nio:type=BufferPool,*"), null);
    pools = new ArrayList<BufferPoolMXBean>();
    for (ObjectName name: mbeans) {
        BufferPoolMXBean pool = ManagementFactory
            .newPlatformMXBeanProxy(server, name.toString(), BufferPoolMXBean.class);
        pools.add(pool);
    }
    check(pools, bufferCount, totalCapacity);

    // attempt to unmap mapped buffer
    WeakReference<MappedByteBuffer> ref = new WeakReference<>(mbb);
    mbb = null;
    do {
        System.gc();
        Thread.sleep(250);
    } while (ref.get() != null);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:Basic.java


注:本文中的java.lang.management.ManagementFactory.newPlatformMXBeanProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。