import javax.management.*;
import javax.management.j2ee.Management;
import javax.naming.InitialContext;
public class ApplicationMonitor {
public static void main(String[] args) throws Exception {
InitialContext ctx = new InitialContext();
MBeanServerConnection connection = (MBeanServerConnection) ctx.lookup("jmx/connection");
ObjectName managementMBeanName = new ObjectName("j2ee:type=Management");
Management managementMBean = Management.newInstanceOf(connection, managementMBeanName);
String applicationName = "MyApplication";
String runtimeState = managementMBean.getApplicationRuntimeState(applicationName);
}
}