BAEL-3060: Cleanup JMXTutorialMainlauncher (#8991)

This commit is contained in:
kwoyke 2020-03-30 23:10:57 +02:00 committed by GitHub
parent 2fb2f89bd4
commit 16e6ddc2e3
1 changed files with 14 additions and 12 deletions

View File

@ -3,7 +3,12 @@ package com.baeldung.jmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.management.*;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;
public class JMXTutorialMainlauncher {
@ -11,24 +16,21 @@ public class JMXTutorialMainlauncher {
private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class);
public static void main(String[] args) {
// TODO Auto-generated method stub
LOG.debug("This is basic JMX tutorial");
ObjectName objectName = null;
try {
objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
} catch (MalformedObjectNameException e) {
e.printStackTrace();
}
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
Game gameObj = new Game();
try {
server.registerMBean(gameObj, objectName);
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
ObjectName objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
server.registerMBean(new Game(), objectName);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException |
MBeanRegistrationException | NotCompliantMBeanException e) {
e.printStackTrace();
}
LOG.debug("Registration for Game mbean with the platform server is successfull");
LOG.debug("Please open jconsole to access Game mbean");
while (true) {
// to ensure application does not terminate
}