You also should use the MBean server that is in tomcat - you have to find that one via:
// find the existing MBean server (tomcat's) in lieu of
// creating our own
//
ArrayList<MBeanServer> mbservers = MBeanServerFactory
.findMBeanServer(null);
int nservers = mbservers.size();
if (nservers > 0) {
//
// TODO: A better way to get the currently active server ?
// For some reason, every time the webapp is reloaded there is one
// more instance of the MBeanServer
mbserver = (MBeanServer) mbservers.get(nservers - 1);
}
if (mbserver == null) {
mbserver = MBeanServerFactory.createMBeanServer();
}