【问题标题】:Getting Dump from weblogic server programatically以编程方式从 weblogic 服务器获取转储
【发布时间】:2014-03-10 12:04:54
【问题描述】:

我有一个要求,我需要设计一个包含按钮的小应用程序。当用户单击它时,它将连接到相应的 weblogic 服务器并为用户下载位于特定位置的 MDS 转储 ZIP 文件。我需要使用 java 语言以编程方式实现这一点,最好使用 MBean。

我是这个 MBean 概念的新手。谁能帮我弄清楚如何找出正确的 MBean 以访问转储文件并下载它们?

【问题讨论】:

    标签: java jmx jdeveloper mbeans


    【解决方案1】:

    我已经做过这样的事情:这里是我所有的代码:

    public class HeapGenerator {
    
    private HeapGenerator() {
    
    }
    
    private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic";
    private static long lastHeapDumpGenrationTime ;
    // field to store the hotspot diagnostic MBean
    private static volatile HotSpotDiagnosticMXBean hotspotMBean;
    
    public static void generateHeapDump(String fileName, boolean live) {
        // initialize hotspot diagnostic MBean
        initHotspotMBean();
        try {
            File dumpFile = new File(fileName);
            if (dumpFile.exists()) {
                dumpFile.delete();
            }
            hotspotMBean.dumpHeap(fileName, live);
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception exp) {
            throw new RuntimeException(exp);
        }
    }
    
    // initialize the hotspot diagnostic MBean field
    private static void initHotspotMBean() {
        if (hotspotMBean == null) {
            synchronized (HeapDumpGenerator.class) {
                if (hotspotMBean == null) {
                    hotspotMBean = getHotspotMBean();
                }
            }
        }
    }
    
    // get the hotspot diagnostic MBean from the
    // platform MBean server
    private static HotSpotDiagnosticMXBean getHotspotMBean() {
        try {
            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
            HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME, HotSpotDiagnosticMXBean.class);
            return bean;
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception exp) {
            throw new RuntimeException(exp);
        }
    }
    
    public static String generateHeapDump() {
        String fileName = getFullHeapDumpFileName();
        generateHeapDump(fileName, true);
        return fileName;
    }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-02-24
      • 1970-01-01
      • 2012-02-02
      • 1970-01-01
      • 2014-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多