- java.lang.Object
-
- java.lang.management.ManagementFactory
-
public class ManagementFactory extends Object
TheManagementFactory
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 MXBeans representing the management interface of a component of the Java virtual machine.Platform MXBeans
A platform MXBean is a managed bean that conforms to the JMX Instrumentation Specification and only uses a set of basic data types. A JMX management application and the platform MBeanServer can interoperate without requiring classes for MXBean specific data types. The data types being transmitted between the JMX connector server and the connector client are open types and this allows interoperation across versions. See the specification of MXBeans for details.
Each platform MXBean is a
PlatformManagedObject
and it has a uniqueObjectName
for registration in the platformMBeanServer
as returned by by thegetObjectName
method.An application can access a platform MXBean in the following ways:
1. Direct access to an MXBean interface
- Get an MXBean instance by calling the
getPlatformMXBean
orgetPlatformMXBeans
method and access the MXBean locally in the running virtual machine. - Construct an MXBean proxy instance that forwards the
method calls to a given
MBeanServer
by calling thegetPlatformMXBean(MBeanServerConnection, Class)
orgetPlatformMXBeans(MBeanServerConnection, Class)
method. ThenewPlatformMXBeanProxy
method can also be used to construct an MXBean proxy instance of a givenObjectName
. A proxy is typically constructed to remotely access an MXBean of another running virtual machine.
2. 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 in the MXBean specification for details.
The
getPlatformManagementInterfaces
method returns all management interfaces supported in the Java virtual machine including the standard management interfaces listed in the tables below as well as the management interfaces extended by the JDK implementation.A Java virtual machine has a single instance of the following management interfaces:
A Java virtual machine has zero or a single instance of the following management interfaces.
Management Interface ObjectName CompilationMXBean
java.lang:type=Compilation
A Java virtual machine may have one or more instances of the following management interfaces.
Management Interface ObjectName GarbageCollectorMXBean
java.lang:type=GarbageCollector
,name=collector's nameMemoryManagerMXBean
java.lang:type=MemoryManager
,name=manager's nameMemoryPoolMXBean
java.lang:type=MemoryPool
,name=pool's nameBufferPoolMXBean
java.nio:type=BufferPool,name=
pool name- Since:
- 1.5
- See Also:
-
JMX Specification,
Ways to Access Management Metrics,
MXBean
- Get an MXBean instance by calling the
-
-
Field Summary
Fields Modifier and Type Field and Description static String
CLASS_LOADING_MXBEAN_NAME
String representation of the ObjectName for theClassLoadingMXBean
.static String
COMPILATION_MXBEAN_NAME
String representation of the ObjectName for theCompilationMXBean
.static String
GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aGarbageCollectorMXBean
.static String
MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aMemoryManagerMXBean
.static String
MEMORY_MXBEAN_NAME
String representation of the ObjectName for theMemoryMXBean
.static String
MEMORY_POOL_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aMemoryPoolMXBean
.static String
OPERATING_SYSTEM_MXBEAN_NAME
String representation of the ObjectName for theOperatingSystemMXBean
.static String
RUNTIME_MXBEAN_NAME
String representation of the ObjectName for theRuntimeMXBean
.static String
THREAD_MXBEAN_NAME
String representation of the ObjectName for theThreadMXBean
.
-
Method Summary
Methods Modifier and Type Method and Description static ClassLoadingMXBean
getClassLoadingMXBean()
Returns the managed bean for the class loading system of the Java virtual machine.static CompilationMXBean
getCompilationMXBean()
Returns the managed bean for the compilation system of the Java virtual machine.static List<GarbageCollectorMXBean>
getGarbageCollectorMXBeans()
Returns a list ofGarbageCollectorMXBean
objects in the Java virtual machine.static List<MemoryManagerMXBean>
getMemoryManagerMXBeans()
Returns a list ofMemoryManagerMXBean
objects in the Java virtual machine.static MemoryMXBean
getMemoryMXBean()
Returns the managed bean for the memory system of the Java virtual machine.static List<MemoryPoolMXBean>
getMemoryPoolMXBeans()
Returns a list ofMemoryPoolMXBean
objects in the Java virtual machine.static OperatingSystemMXBean
getOperatingSystemMXBean()
Returns the managed bean for the operating system on which the Java virtual machine is running.static Set<Class<? extends PlatformManagedObject>>
getPlatformManagementInterfaces()
Returns the set ofClass
objects, subinterface ofPlatformManagedObject
, representing all management interfaces for monitoring and managing the Java platform.static MBeanServer
getPlatformMBeanServer()
Returns the platformMBeanServer
.static <T extends PlatformManagedObject>
TgetPlatformMXBean(Class<T> mxbeanInterface)
Returns the platform MXBean implementing the givenmxbeanInterface
which is specified to have one single instance in the Java virtual machine.static <T extends PlatformManagedObject>
TgetPlatformMXBean(MBeanServerConnection connection, Class<T> mxbeanInterface)
Returns the platform MXBean proxy formxbeanInterface
which is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the givenMBeanServerConnection
.static <T extends PlatformManagedObject>
List<T>getPlatformMXBeans(Class<T> mxbeanInterface)
Returns the list of platform MXBeans implementing the givenmxbeanInterface
in the Java virtual machine.static <T extends PlatformManagedObject>
List<T>getPlatformMXBeans(MBeanServerConnection connection, Class<T> mxbeanInterface)
Returns the list of the platform MXBean proxies for forwarding the method calls of themxbeanInterface
through the givenMBeanServerConnection
.static RuntimeMXBean
getRuntimeMXBean()
Returns the managed bean for the runtime system of the Java virtual machine.static ThreadMXBean
getThreadMXBean()
Returns the managed bean for the thread system of the Java virtual machine.static <T> T
newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface)
Returns a proxy for a platform MXBean interface of a given MXBean name that forwards its method calls through the given MBeanServerConnection.
-
-
-
Field Detail
-
CLASS_LOADING_MXBEAN_NAME
public static final String CLASS_LOADING_MXBEAN_NAME
String representation of the ObjectName for theClassLoadingMXBean
.- See Also:
- Constant Field Values
-
COMPILATION_MXBEAN_NAME
public static final String COMPILATION_MXBEAN_NAME
String representation of the ObjectName for theCompilationMXBean
.- See Also:
- Constant Field Values
-
MEMORY_MXBEAN_NAME
public static final String MEMORY_MXBEAN_NAME
String representation of the ObjectName for theMemoryMXBean
.- See Also:
- Constant Field Values
-
OPERATING_SYSTEM_MXBEAN_NAME
public static final String OPERATING_SYSTEM_MXBEAN_NAME
String representation of the ObjectName for theOperatingSystemMXBean
.- See Also:
- Constant Field Values
-
RUNTIME_MXBEAN_NAME
public static final String RUNTIME_MXBEAN_NAME
String representation of the ObjectName for theRuntimeMXBean
.- See Also:
- Constant Field Values
-
THREAD_MXBEAN_NAME
public static final String THREAD_MXBEAN_NAME
String representation of the ObjectName for theThreadMXBean
.- See Also:
- Constant Field Values
-
GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
public static final String GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aGarbageCollectorMXBean
. The unique ObjectName for a GarbageCollectorMXBean can be formed by appending this string with ",name=collector's name".- See Also:
- Constant Field Values
-
MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
public static final String MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aMemoryManagerMXBean
. The unique ObjectName for a MemoryManagerMXBean can be formed by appending this string with ",name=manager's name".- See Also:
- Constant Field Values
-
MEMORY_POOL_MXBEAN_DOMAIN_TYPE
public static final String MEMORY_POOL_MXBEAN_DOMAIN_TYPE
The domain name and the type key property in the ObjectName for aMemoryPoolMXBean
. The unique ObjectName for a MemoryPoolMXBean can be formed by appending this string with ,name=pool's name.- See Also:
- Constant Field Values
-
-
Method Detail
-
getClassLoadingMXBean
public static ClassLoadingMXBean getClassLoadingMXBean()
Returns the managed bean for the class loading system of the Java virtual machine.- Returns:
- a
ClassLoadingMXBean
object for the Java virtual machine.
-
getMemoryMXBean
public static MemoryMXBean getMemoryMXBean()
Returns the managed bean for the memory system of the Java virtual machine.- Returns:
- a
MemoryMXBean
object for the Java virtual machine.
-
getThreadMXBean
public static ThreadMXBean getThreadMXBean()
Returns the managed bean for the thread system of the Java virtual machine.- Returns:
- a
ThreadMXBean
object for the Java virtual machine.
-
getRuntimeMXBean
public static RuntimeMXBean getRuntimeMXBean()
Returns the managed bean for the runtime system of the Java virtual machine.- Returns:
- a
RuntimeMXBean
object for the Java virtual machine.
-
getCompilationMXBean
public static CompilationMXBean getCompilationMXBean()
Returns the managed bean for the compilation system of the Java virtual machine. This method returns null if the Java virtual machine has no compilation system.- Returns:
- a
CompilationMXBean
object for the Java virtual machine or null if the Java virtual machine has no compilation system.
-
getOperatingSystemMXBean
public static OperatingSystemMXBean getOperatingSystemMXBean()
Returns the managed bean for the operating system on which the Java virtual machine is running.- Returns:
- an
OperatingSystemMXBean
object for the Java virtual machine.
-
getMemoryPoolMXBeans
public static List<MemoryPoolMXBean> getMemoryPoolMXBeans()
Returns a list ofMemoryPoolMXBean
objects in the Java virtual machine. The Java virtual machine can have one or more memory pools. It may add or remove memory pools during execution.- Returns:
- a list of MemoryPoolMXBean objects.
-
getMemoryManagerMXBeans
public static List<MemoryManagerMXBean> getMemoryManagerMXBeans()
Returns a list ofMemoryManagerMXBean
objects in the Java virtual machine. The Java virtual machine can have one or more memory managers. It may add or remove memory managers during execution.- Returns:
- a list of MemoryManagerMXBean objects.
-
getGarbageCollectorMXBeans
public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans()
Returns a list ofGarbageCollectorMXBean
objects in the Java virtual machine. The Java virtual machine may have one or more GarbageCollectorMXBean objects. It may add or remove GarbageCollectorMXBean during execution.- Returns:
- a list of GarbageCollectorMXBean objects.
-
getPlatformMBeanServer
public static MBeanServer getPlatformMBeanServer()
Returns the platformMBeanServer
. On the first call to this method, it first creates the platformMBeanServer
by calling theMBeanServerFactory.createMBeanServer
method and registers each platform MXBean in this platformMBeanServer
with itsObjectName
. This method, in subsequent calls, will simply return the initially created platformMBeanServer
.MXBeans that get created and destroyed dynamically, for example, memory
pools
andmanagers
, will automatically be registered and deregistered into the platformMBeanServer
.If the system property
javax.management.builder.initial
is set, the platformMBeanServer
creation will be done by the specifiedMBeanServerBuilder
.It is recommended that this platform MBeanServer also be used to register other application managed beans besides the platform MXBeans. This will allow all MBeans to be published through the same
MBeanServer
and hence allow for easier network publishing and discovery. Name conflicts with the platform MXBeans should be avoided.- Returns:
- the platform
MBeanServer
; the platform MXBeans are registered into the platformMBeanServer
at the first time this method is called. - Throws:
SecurityException
- if there is a security manager and the caller does not have the permission required byMBeanServerFactory.createMBeanServer()
.- See Also:
MBeanServerFactory
,MBeanServerFactory.createMBeanServer()
-
newPlatformMXBeanProxy
public static <T> T newPlatformMXBeanProxy(MBeanServerConnection connection, String mxbeanName, Class<T> mxbeanInterface) throws IOException
Returns a proxy for a platform MXBean interface of a given MXBean name that forwards its method calls through the given MBeanServerConnection.This method is equivalent to:
Proxy.newProxyInstance
(mxbeanInterface.getClassLoader(), new Class[] { mxbeanInterface }, handler)InvocationHandler
to which method invocations to the MXBean interface are dispatched. This handler converts an input parameter from an MXBean data type to its mapped open type before forwarding to the MBeanServer and converts a return value from an MXBean method call through the MBeanServer from an open type to the corresponding return type declared in the MXBean interface.If the MXBean is a notification emitter (i.e., it implements
NotificationEmitter
), both the mxbeanInterface and NotificationEmitter will be implemented by this proxy.Notes:
- Using an MXBean proxy is a convenience remote access to
a platform MXBean of a running virtual machine. All method
calls to the MXBean proxy are forwarded to an
MBeanServerConnection where
IOException
may be thrown when the communication problem occurs with the connector server. An application remotely accesses the platform MXBeans using proxy should prepare to catch IOException as if accessing with the MBeanServerConnector interface. - When a client application is designed to remotely access MXBeans
for a running virtual machine whose version is different than
the version on which the application is running,
it should prepare to catch
InvalidObjectException
which is thrown when an MXBean proxy receives a name of an enum constant which is missing in the enum class loaded in the client application. MBeanServerInvocationHandler
or itsnewProxyInstance
method cannot be used to create a proxy for a platform MXBean. The proxy object created by MBeanServerInvocationHandler does not handle the properties of the platform MXBeans described in the class specification.
- Parameters:
connection
- the MBeanServerConnection to forward to.mxbeanName
- the name of a platform MXBean within connection to forward to. mxbeanName must be in the format ofObjectName
.mxbeanInterface
- the MXBean interface to be implemented by the proxy.- Throws:
IllegalArgumentException
- if- mxbeanName is not with a valid
ObjectName
format, or - the named MXBean in the connection is not a MXBean provided by the platform, or
- the named MXBean is not registered in the MBeanServerConnection, or
- the named MXBean is not an instance of the given mxbeanInterface
- mxbeanName is not with a valid
IOException
- if a communication problem occurred when accessing the MBeanServerConnection.
- Using an MXBean proxy is a convenience remote access to
a platform MXBean of a running virtual machine. All method
calls to the MXBean proxy are forwarded to an
MBeanServerConnection where
-
getPlatformMXBean
public static <T extends PlatformManagedObject> T getPlatformMXBean(Class<T> mxbeanInterface)
Returns the platform MXBean implementing the givenmxbeanInterface
which is specified to have one single instance in the Java virtual machine. This method may returnnull
if the management interface is not implemented in the Java virtual machine (for example, a Java virtual machine with no compilation system does not implementCompilationMXBean
); otherwise, this method is equivalent to calling:getPlatformMXBeans(mxbeanInterface)
.get(0);- Parameters:
mxbeanInterface
- a management interface for a platform MXBean with one single instance in the Java virtual machine if implemented.- Returns:
- the platform MXBean that implements
mxbeanInterface
, ornull
if not exist. - Throws:
IllegalArgumentException
- ifmxbeanInterface
is not a platform management interface or not a singleton platform MXBean.- Since:
- 1.7
-
getPlatformMXBeans
public static <T extends PlatformManagedObject> List<T> getPlatformMXBeans(Class<T> mxbeanInterface)
Returns the list of platform MXBeans implementing the givenmxbeanInterface
in the Java virtual machine. The returned list may contain zero, one, or more instances. The number of instances in the returned list is defined in the specification of the given management interface. The order is undefined and there is no guarantee that the list returned is in the same order as previous invocations.- Parameters:
mxbeanInterface
- a management interface for a platform MXBean- Returns:
- the list of platform MXBeans that implement
mxbeanInterface
. - Throws:
IllegalArgumentException
- ifmxbeanInterface
is not a platform management interface.- Since:
- 1.7
-
getPlatformMXBean
public static <T extends PlatformManagedObject> T getPlatformMXBean(MBeanServerConnection connection, Class<T> mxbeanInterface) throws IOException
Returns the platform MXBean proxy formxbeanInterface
which is specified to have one single instance in a Java virtual machine and the proxy will forward the method calls through the givenMBeanServerConnection
. This method may returnnull
if the management interface is not implemented in the Java virtual machine being monitored (for example, a Java virtual machine with no compilation system does not implementCompilationMXBean
); otherwise, this method is equivalent to calling:getPlatformMXBeans(connection, mxbeanInterface)
.get(0);- Parameters:
connection
- theMBeanServerConnection
to forward to.mxbeanInterface
- a management interface for a platform MXBean with one single instance in the Java virtual machine being monitored, if implemented.- Returns:
- the platform MXBean proxy for
forwarding the method calls of the
mxbeanInterface
through the givenMBeanServerConnection
, ornull
if not exist. - Throws:
IllegalArgumentException
- ifmxbeanInterface
is not a platform management interface or not a singleton platform MXBean.IOException
- if a communication problem occurred when accessing theMBeanServerConnection
.- Since:
- 1.7
- See Also:
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
-
getPlatformMXBeans
public static <T extends PlatformManagedObject> List<T> getPlatformMXBeans(MBeanServerConnection connection, Class<T> mxbeanInterface) throws IOException
Returns the list of the platform MXBean proxies for forwarding the method calls of themxbeanInterface
through the givenMBeanServerConnection
. The returned list may contain zero, one, or more instances. The number of instances in the returned list is defined in the specification of the given management interface. The order is undefined and there is no guarantee that the list returned is in the same order as previous invocations.- Parameters:
connection
- theMBeanServerConnection
to forward to.mxbeanInterface
- a management interface for a platform MXBean- Returns:
- the list of platform MXBean proxies for
forwarding the method calls of the
mxbeanInterface
through the givenMBeanServerConnection
. - Throws:
IllegalArgumentException
- ifmxbeanInterface
is not a platform management interface.IOException
- if a communication problem occurred when accessing theMBeanServerConnection
.- Since:
- 1.7
- See Also:
newPlatformMXBeanProxy(javax.management.MBeanServerConnection, java.lang.String, java.lang.Class<T>)
-
getPlatformManagementInterfaces
public static Set<Class<? extends PlatformManagedObject>> getPlatformManagementInterfaces()
Returns the set ofClass
objects, subinterface ofPlatformManagedObject
, representing all management interfaces for monitoring and managing the Java platform.- Returns:
- the set of
Class
objects, subinterface ofPlatformManagedObject
representing the management interfaces for monitoring and managing the Java platform. - Since:
- 1.7
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/lang/management/managementfactory.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.