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


Java GaugeMonitorMBean类代码示例

本文整理汇总了Java中javax.management.monitor.GaugeMonitorMBean的典型用法代码示例。如果您正苦于以下问题:Java GaugeMonitorMBean类的具体用法?Java GaugeMonitorMBean怎么用?Java GaugeMonitorMBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: doSensitiveThing

import javax.management.monitor.GaugeMonitorMBean; //导入依赖的package包/类
abstract void doSensitiveThing(GaugeMonitorMBean monitorProxy,
ObjectName observedName);
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:3,代码来源:GaugeMonitorDeadlockTest.java

示例2: run

import javax.management.monitor.GaugeMonitorMBean; //导入依赖的package包/类
void run() throws Exception {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    final ObjectName observedName = new ObjectName("a:b=c");
    final ObjectName monitorName = new ObjectName("a:type=Monitor");
    mbs.registerMBean(new GaugeMonitor(), monitorName);
    final GaugeMonitorMBean monitorProxy =
        JMX.newMBeanProxy(mbs, monitorName, GaugeMonitorMBean.class);
    final TestMBean observedProxy =
        JMX.newMBeanProxy(mbs, observedName, TestMBean.class);

    final Runnable sensitiveThing = new Runnable() {
        public void run() {
            doSensitiveThing(monitorProxy, observedName);
        }
    };

    final Runnable nothing = new Runnable() {
        public void run() {}
    };

    final Runnable withinGetAttribute =
        (when == When.IN_GET_ATTRIBUTE) ? sensitiveThing : nothing;

    mbs.registerMBean(new Test(withinGetAttribute), observedName);
    monitorProxy.addObservedObject(observedName);
    monitorProxy.setObservedAttribute("Thing");
    monitorProxy.setThresholds(105, 100);
    monitorProxy.setGranularityPeriod(10L); // 10 ms
    monitorProxy.setNotifyHigh(true);
    monitorProxy.setNotifyLow(true);
    monitorProxy.start();

    final int initGetCount = observedProxy.getGetCount();
    int getCount = initGetCount;
    for (int i = 0; i < 2000; i++) { // 2000 * 10 = 20 seconds
        getCount = observedProxy.getGetCount();
        if (getCount != initGetCount)
            break;
        Thread.sleep(10);
    }
    if (getCount <= initGetCount)
        throw new Exception("Test failed: presumable deadlock");
    // This won't show up as a deadlock in CTRL-\ or in
    // ThreadMXBean.findDeadlockedThreads(), because they don't
    // see that thread A is waiting for thread B (B.join()), and
    // thread B is waiting for a lock held by thread A

    // Now we know the monitor has observed the initial value,
    // so if we want to test notify behaviour we can trigger by
    // exceeding the threshold.
    if (when == When.IN_NOTIFY) {
        final AtomicInteger notifCount = new AtomicInteger();
        final NotificationListener listener = new NotificationListener() {
            public void handleNotification(Notification n, Object h) {
                Thread t = new Thread(sensitiveThing);
                t.start();
                try {
                    t.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                notifCount.incrementAndGet();
            }
        };
        mbs.addNotificationListener(monitorName, listener, null, null);
        observedProxy.setThing(1000);
        for (int i = 0; i < 2000 && notifCount.get() == 0; i++)
            Thread.sleep(10);
        if (notifCount.get() == 0)
            throw new Exception("Test failed: presumable deadlock");
    }

}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:74,代码来源:GaugeMonitorDeadlockTest.java


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