国产探花免费观看_亚洲丰满少妇自慰呻吟_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調用,并不需要新開端口


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灌阳县| 饶平县| 锦屏县| 杭锦旗| 肥东县| 渭南市| 中西区| 南丰县| 苗栗市| 焦作市| 高青县| 铜梁县| 辽阳县| 华阴市| 容城县| 庄河市| 读书| 嫩江县| 怀化市| 黑河市| 射洪县| 黑水县| 辽源市| 岗巴县| 安福县| 钟山县| 安图县| 桂东县| 平泉县| 黑龙江省| 金湖县| 黎川县| 阳高县| 襄垣县| 松滋市| 佛教| 佛教| 门源| 井冈山市| 简阳市| 海淀区|