国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

在一臺機器上通過JMX進行跨JVM的本地調用

2019-11-08 02:21:52
字體:
來源:轉載
供稿:網友
import java.io.File;import java.io.IOException;import java.util.PRoperties;import javax.management.MBeanServerConnection;import javax.management.remote.JMXConnector;import javax.management.remote.JMXConnectorFactory;import javax.management.remote.JMXServiceURL;import com.sun.tools.attach.AgentInitializationException;import com.sun.tools.attach.AgentLoadException;import com.sun.tools.attach.AttachNotSupportedException;import com.sun.tools.attach.VirtualMachine;/** * * 通過jmx本地連接 */public class JmxLocalConnector { private VirtualMachine virtualmachine; private JMXConnector connector; /** * *pid為連接的進程id */ public MBeanServerConnection connect(String pid) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { String address = attachJmx(pid); JMXServiceURL serviceURL = new JMXServiceURL(address); connector = JMXConnectorFactory.connect(serviceURL); return connector.getMBeanServerConnection(); } public void disConnect() { if (virtualmachine != null) { try { virtualmachine.detach(); } catch (IOException e) { e.printStackTrace(); } } if (connector != null) { try { connector.close(); } catch (IOException e) { e.printStackTrace(); } } } private String attachJmx(String pid) throws IOException, AttachNotSupportedException, AgentLoadException, AgentInitializationException { virtualmachine = VirtualMachine.attach(pid); String javaHome = virtualmachine.getSystemProperties().getProperty("java.home"); String agentPath = javaHome + File.separator + "jre" + File.separator + "lib" + File.separator + "management-agent.jar"; File file = new File(agentPath); if (!file.exists()) { agentPath = javaHome + File.separator + "lib" + File.separator + "management-agent.jar"; file = new File(agentPath); if (!file.exists()) throw new IOException("Management agent not found"); } agentPath = file.getCanonicalPath(); virtualmachine.loadAgent(agentPath, "com.sun.management.jmxremote"); Properties properties = virtualmachine.getAgentProperties(); String address = (String) properties.get("com.sun.management.jmxremote.localConnectorAddress"); virtualmachine.detach(); return address; }}

通過以上方式創建出MBeanServerConnection ,即可通過它對另一個JVM進行JMX調用,并不需要新開端口


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 克山县| 扎兰屯市| 广灵县| 吴川市| 佛冈县| 赤城县| 彭泽县| 松滋市| 玉山县| 龙泉市| 运城市| 中江县| 蓬溪县| 武隆县| 江城| 教育| 剑川县| 钦州市| 安国市| 长宁区| 宿松县| 图们市| 正安县| 南岸区| 平阴县| 吴江市| 桦川县| 屯门区| 洛扎县| 安新县| 竹溪县| 玛沁县| 中卫市| 淅川县| 和平区| 民和| 木兰县| 靖宇县| 中阳县| 富平县| 台山市|