本文整理匯總了Java中javax.management.remote.JMXServiceURL.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java JMXServiceURL.toString方法的具體用法?Java JMXServiceURL.toString怎麽用?Java JMXServiceURL.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.remote.JMXServiceURL
的用法示例。
在下文中一共展示了JMXServiceURL.toString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: start
import javax.management.remote.JMXServiceURL; //導入方法依賴的package包/類
public static String start() throws Exception {
int serverPort = 12345;
ObjectName name = new ObjectName("test", "foo", "bar");
MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
SteMBean bean = new Ste();
jmxServer.registerMBean(bean, name);
boolean exported = false;
Random rnd = new Random(System.currentTimeMillis());
do {
try {
LocateRegistry.createRegistry(serverPort);
exported = true;
} catch (ExportException ee) {
if (ee.getCause() instanceof BindException) {
serverPort = rnd.nextInt(10000) + 4096;
} else {
throw ee;
}
}
} while (!exported);
JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
jmxConnector.start();
return serverUrl.toString();
}