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