Пример #1
0
  public static void main(String[] argv) throws Exception {
    memory = new ObjectName(MEMORY_MXBEAN_NAME);
    runtime = new ObjectName(RUNTIME_MXBEAN_NAME);
    thread = new ObjectName(THREAD_MXBEAN_NAME);
    os = new ObjectName(OPERATING_SYSTEM_MXBEAN_NAME);

    List<MemoryPoolMXBean> pools = getMemoryPoolMXBeans();
    for (MemoryPoolMXBean p : pools) {
      if (heapPool == null
          && p.getType() == MemoryType.HEAP
          && p.isUsageThresholdSupported()
          && p.isCollectionUsageThresholdSupported()) {
        heapPool = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + p.getName());
      }
      if (nonHeapPool == null
          && p.getType() == MemoryType.NON_HEAP
          && p.isUsageThresholdSupported()) {
        nonHeapPool = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",name=" + p.getName());
      }
    }

    // Check notification emitters
    MyListener listener = new MyListener();
    server.addNotificationListener(memory, listener, null, null);
    server.removeNotificationListener(memory, listener);

    checkEnum();
    checkList();
    checkMap();
    checkMemoryUsage();
    checkThreadInfo();

    checkOS();
    checkSunGC();

    System.out.println("Test passed.");
  }