The ManagementFactory class is a factory class for getting managed beans for the Java platform. This class consists of static methods each of which returns one or more platform MXBean(s) representing the management interface of a component of the Java virtual machine.
An application can access a platform MXBean in the following ways:
- Direct access to an MXBean interface
- Get the MXBean instance through the static factory method and access the MXBean locally of the running virtual machine.
- Construct an MXBean proxy instance that forwards the method calls to a given
MBeanServer
by callingnewPlatfromMXBeanProxy
. A proxy is typically constructed to remotely access an MXBean of another running virtual machine.
- Indirect access to an MXBean interface via MBeanServer
- Go through the
platform MBeanServer
to access MXBeans locally or a specific MBeanServerConnection to access MXBeans remotely. The attributes and operations of an MXBean use only JMX open types which include basic data types,CompositeData
, andTabularData
defined inOpenType
. The mapping is specified below.
- Go through the
Below is a simple Java Program which returns Start Time and Date
of a JVM.
package com.crunchify.tutorials; /** * @author Crunchify.com */ import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class CrunchifyGetJVMTime { public static void main(String[] args) { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); long startTime = runtimeBean.getStartTime(); Date startDate = new Date(startTime); System.out.println("\nStart Time in millisecond = " + startTime); System.out.println("Start Date = " + startDate); } }
Output:
Start Time = 1367269277031 Start Date = Mon Apr 29 14:01:17 PDT 2013