public class JVM
extends java.lang.Object
| 限定符和类型 | 方法和说明 |
|---|---|
java.lang.management.ThreadInfo[] |
dumpAllThreads(boolean lockedMonitors,
boolean lockedSynchronizers)
Returns the thread info for all live threads with stack trace
and synchronization information.
|
long[] |
findDeadlockedThreads()
Finds cycles of threads that are in deadlock waiting to acquire
object monitors or
ownable synchronizers.
|
long[] |
findMonitorDeadlockedThreads()
Finds cycles of threads that are in deadlock waiting to acquire
object monitors.
|
void |
gc()
Runs the garbage collector.
|
long[] |
getAllThreadIds()
Returns all live thread IDs.
|
java.lang.String |
getArch()
Returns the operating system architecture.
|
int |
getAvailableProcessors()
Returns the number of processors available to the Java virtual machine.
|
java.lang.String |
getBootClassPath()
Returns the boot class path that is used by the bootstrap class loader
to search for class files.
|
java.lang.String |
getClassPath()
Returns the Java class path that is used by the system class loader
to search for class files.
|
long |
getCurrentThreadCpuTime()
Returns the total CPU time for the current thread in nanoseconds.
|
long |
getCurrentThreadUserTime()
Returns the CPU time that the current thread has executed
in user mode in nanoseconds.
|
int |
getDaemonThreadCount()
Returns the current number of live daemon threads.
|
java.util.List<java.lang.management.GarbageCollectorMXBean> |
getGarbageCollectorMXBeans() |
java.lang.management.MemoryUsage |
getHeapMemoryUsage()
Returns the current memory usage of the heap that
is used for object allocation.
|
java.util.List<java.lang.String> |
getInputArguments()
Returns the input arguments passed to the Java virtual machine
which does not include the arguments to the main method.
|
static JVM |
getInstance() |
java.lang.String |
getLibraryPath()
Returns the Java library path.
|
int |
getLoadedClassCount()
返回当前加载到 Java 虚拟机中的类的数量
Returns the number of classes that are currently loaded in the
Java virtual machine.
|
java.lang.String |
getManagementSpecVersion()
Returns the version of the specification for the management interface
implemented by the running Java virtual machine.
|
java.util.List<java.lang.management.MemoryPoolMXBean> |
getMemoryPoolMXBeans() |
java.lang.String |
getName()
Returns the name representing the running Java virtual machine.
|
java.lang.management.MemoryUsage |
getNonHeapMemoryUsage()
Returns the current memory usage of non-heap memory that
is used by the Java virtual machine.
|
int |
getObjectPendingFinalizationCount()
Returns the approximate number of objects for which
finalization is pending.
|
int |
getPeakThreadCount()
返回自从 Java 虚拟机启动或峰值重置以来峰值活动线程计数
Returns the peak live thread count since the Java virtual machine
started or peak was reset.
|
java.lang.String |
getSpecName()
Returns the Java virtual machine specification name.
|
java.lang.String |
getSpecVendor()
Returns the Java virtual machine specification vendor.
|
java.lang.String |
getSpecVersion()
Returns the Java virtual machine specification version.
|
long |
getStartTime()
返回 Java 虚拟机的启动时间(以毫秒为单位)
Returns the start time of the Java virtual machine in milliseconds.
|
double |
getSystemLoadAverage()
返回最后一分钟内系统加载平均值
Returns the system load average for the last minute.
|
java.util.Map<java.lang.String,java.lang.String> |
getSystemProperties()
Returns a map of names and values of all system properties.
|
int |
getThreadCount()
返回活动线程的当前数目,包括守护线程和非守护线程
Returns the current number of live threads including both
daemon and non-daemon threads.
|
long |
getThreadCpuTime(long id)
Returns the total CPU time for a thread of the specified ID in nanoseconds.
|
java.lang.management.ThreadInfo |
getThreadInfo(long id)
Returns the thread info for a thread of the specified
id with no stack trace.
|
java.lang.management.ThreadInfo[] |
getThreadInfo(long[] ids)
Returns the thread info for each thread
whose ID is in the input array ids with no stack trace.
|
java.lang.management.ThreadInfo[] |
getThreadInfo(long[] ids,
boolean lockedMonitors,
boolean lockedSynchronizers)
Returns the thread info for each thread
whose ID is in the input array ids, with stack trace
and synchronization information.
|
java.lang.management.ThreadInfo[] |
getThreadInfo(long[] ids,
int maxDepth)
Returns the thread info for each thread
whose ID is in the input array ids,
with stack trace of a specified number of stack trace elements.
|
java.lang.management.ThreadInfo |
getThreadInfo(long id,
int maxDepth)
Returns a thread info for a thread of the specified id,
with stack trace of a specified number of stack trace elements.
|
long |
getThreadUserTime(long id)
Returns the CPU time that a thread of the specified ID
has executed in user mode in nanoseconds.
|
long |
getTotalLoadedClassCount()
返回自 Java 虚拟机开始执行到目前已经加载的类的总数
Returns the total number of classes that have been loaded since
the Java virtual machine has started execution.
|
long |
getTotalStartedThreadCount()
返回自从 Java 虚拟机启动以来创建和启动的线程总数目
Returns the total number of threads created and also started
since the Java virtual machine started.
|
long |
getUnloadedClassCount()
返回自 Java 虚拟机开始执行到目前已经卸载的类的总数
Returns the total number of classes unloaded since the Java virtual machine
has started execution.
|
long |
getUptime()
返回 Java 虚拟机的正常运行时间(以毫秒为单位)
Returns the uptime of the Java virtual machine in milliseconds.
|
java.lang.String |
getVersion()
Returns the operating system version.
|
java.lang.String |
getVmName()
Returns the Java virtual machine implementation name.
|
java.lang.String |
getVmVendor()
Returns the Java virtual machine implementation vendor.
|
java.lang.String |
getVmVersion()
Returns the Java virtual machine implementation version.
|
boolean |
isBootClassPathSupported()
Tests if the Java virtual machine supports the boot class path
mechanism used by the bootstrap class loader to search for class
files.
|
boolean |
isCurrentThreadCpuTimeSupported()
Tests if the Java virtual machine supports CPU time
measurement for the current thread.
|
boolean |
isObjectMonitorUsageSupported()
Tests if the Java virtual machine supports monitoring of
object monitor usage.
|
boolean |
isSynchronizerUsageSupported()
Tests if the Java virtual machine supports monitoring of
ownable synchronizer usage.
|
boolean |
isThreadContentionMonitoringEnabled()
Tests if thread contention monitoring is enabled.
|
boolean |
isThreadContentionMonitoringSupported()
Tests if the Java virtual machine supports thread contention monitoring.
|
boolean |
isThreadCpuTimeEnabled()
Tests if thread CPU time measurement is enabled.
|
boolean |
isThreadCpuTimeSupported()
Tests if the Java virtual machine implementation supports CPU time
measurement for any thread.
|
void |
resetPeakThreadCount()
Resets the peak thread count to the current number of
live threads.
|
void |
setThreadContentionMonitoringEnabled(boolean enable)
Enables or disables thread contention monitoring.
|
void |
setThreadCpuTimeEnabled(boolean enable)
Enables or disables thread CPU time measurement.
|
public static JVM getInstance()
public java.util.List<java.lang.management.GarbageCollectorMXBean> getGarbageCollectorMXBeans()
public java.util.List<java.lang.management.MemoryPoolMXBean> getMemoryPoolMXBeans()
public int getObjectPendingFinalizationCount()
public java.lang.management.MemoryUsage getHeapMemoryUsage()
The amount of used memory in the returned memory usage is the amount of memory occupied by both live objects and garbage objects that have not been collected, if any.
MBeanServer access:
The mapped type of MemoryUsage is
CompositeData with attributes as specified in
MemoryUsage.
MemoryUsage object representing
the heap memory usage.public java.lang.management.MemoryUsage getNonHeapMemoryUsage()
MBeanServer access:
The mapped type of MemoryUsage is
CompositeData with attributes as specified in
MemoryUsage.
MemoryUsage object representing
the non-heap memory usage.public void gc()
gc() is effectively equivalent to the
call:
System.gc()
System.gc()public java.lang.String getArch()
java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getVersion()
java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public int getAvailableProcessors()
Runtime.availableProcessors()
method.
This value may change during a particular invocation of the virtual machine.
public double getSystemLoadAverage()
If the load average is not available, a negative value is returned.
This method is designed to provide a hint about the system load and may be queried frequently. The load average may be unavailable on some platform where it is expensive to implement this method.
public long getTotalLoadedClassCount()
public int getLoadedClassCount()
public long getUnloadedClassCount()
public int getThreadCount()
public int getPeakThreadCount()
public long getTotalStartedThreadCount()
public int getDaemonThreadCount()
public long[] getAllThreadIds()
java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").public java.lang.management.ThreadInfo getThreadInfo(long id)
getThreadInfo(id, 0);
This method returns a ThreadInfo object representing the thread information for the thread of the specified ID. The stack trace, locked monitors, and locked synchronizers in the returned ThreadInfo object will be empty. If a thread of the given ID is not alive or does not exist, this method will return null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in the
ThreadInfo.from method.
id - the thread ID of the thread. Must be positive.ThreadInfo object for the thread of the given ID
with no stack trace, no locked monitor and no synchronizer info;
null if the thread of the given ID is not alive or
it does not exist.java.lang.IllegalArgumentException - if id <= 0.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").public java.lang.management.ThreadInfo[] getThreadInfo(long[] ids)
getThreadInfo(ids, 0);
This method returns an array of the ThreadInfo objects. The stack trace, locked monitors, and locked synchronizers in each ThreadInfo object will be empty. If a thread of a given ID is not alive or does not exist, the corresponding element in the returned array will contain null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in the
ThreadInfo.from method.
ids - an array of thread IDs.ThreadInfo objects, each containing
information about a thread whose ID is in the corresponding
element of the input array of IDs
with no stack trace, no locked monitor and no synchronizer info.java.lang.IllegalArgumentException - if any element in the input array
ids is <= 0.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").public java.lang.management.ThreadInfo getThreadInfo(long id,
int maxDepth)
StackTraceElement to be retrieved from the stack trace.
If maxDepth == Integer.MAX_VALUE, the entire stack trace of
the thread will be dumped.
If maxDepth == 0, no stack trace of the thread
will be dumped.
This method does not obtain the locked monitors and locked
synchronizers of the thread.
When the Java virtual machine has no stack trace information about a thread or maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array of StackTraceElement.
If a thread of the given ID is not alive or does not exist, this method will return null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in the
ThreadInfo.from method.
id - the thread ID of the thread. Must be positive.maxDepth - the maximum number of entries in the stack trace
to be dumped. Integer.MAX_VALUE could be used to request
the entire stack to be dumped.ThreadInfo of the thread of the given ID
with no locked monitor and synchronizer info.
null if the thread of the given ID is not alive or
it does not exist.java.lang.IllegalArgumentException - if id <= 0.java.lang.IllegalArgumentException - if maxDepth is negative.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").public java.lang.management.ThreadInfo[] getThreadInfo(long[] ids,
int maxDepth)
StackTraceElement to be retrieved from the stack trace.
If maxDepth == Integer.MAX_VALUE, the entire stack trace of
the thread will be dumped.
If maxDepth == 0, no stack trace of the thread
will be dumped.
This method does not obtain the locked monitors and locked
synchronizers of the threads.
When the Java virtual machine has no stack trace information about a thread or maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array of StackTraceElement.
This method returns an array of the ThreadInfo objects, each is the thread information about the thread with the same index as in the ids array. If a thread of the given ID is not alive or does not exist, null will be set in the corresponding element in the returned array. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in the
ThreadInfo.from method.
ids - an array of thread IDsmaxDepth - the maximum number of entries in the stack trace
to be dumped. Integer.MAX_VALUE could be used to request
the entire stack to be dumped.ThreadInfo objects, each containing
information about a thread whose ID is in the corresponding
element of the input array of IDs with no locked monitor and
synchronizer info.java.lang.IllegalArgumentException - if maxDepth is negative.java.lang.IllegalArgumentException - if any element in the input array
ids is <= 0.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").public boolean isThreadContentionMonitoringSupported()
public boolean isThreadContentionMonitoringEnabled()
java.lang.UnsupportedOperationException - if the Java virtual
machine does not support thread contention monitoring.isThreadContentionMonitoringSupported()public void setThreadContentionMonitoringEnabled(boolean enable)
enable - true to enable;
false to disable.java.lang.UnsupportedOperationException - if the Java
virtual machine does not support thread contention monitoring.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("control").isThreadContentionMonitoringSupported()public long getCurrentThreadCpuTime()
This is a convenient method for local management use and is equivalent to calling:
getThreadCpuTime(Thread.currentThread().getId());
java.lang.UnsupportedOperationException - if the Java
virtual machine does not support CPU time measurement for
the current thread.getCurrentThreadUserTime(),
isCurrentThreadCpuTimeSupported(),
isThreadCpuTimeEnabled(),
setThreadCpuTimeEnabled(boolean)public long getCurrentThreadUserTime()
This is a convenient method for local management use and is equivalent to calling:
getThreadUserTime(Thread.currentThread().getId());
java.lang.UnsupportedOperationException - if the Java
virtual machine does not support CPU time measurement for
the current thread.getCurrentThreadCpuTime(),
isCurrentThreadCpuTimeSupported(),
isThreadCpuTimeEnabled(),
setThreadCpuTimeEnabled(boolean)public long getThreadCpuTime(long id)
If the thread of the specified ID is not alive or does not exist, this method returns -1. If CPU time measurement is disabled, this method returns -1. A thread is alive if it has been started and has not yet died.
If CPU time measurement is enabled after the thread has started, the Java virtual machine implementation may choose any time up to and including the time that the capability is enabled as the point where CPU time measurement starts.
id - the thread ID of a threadjava.lang.IllegalArgumentException - if id <= 0.java.lang.UnsupportedOperationException - if the Java
virtual machine does not support CPU time measurement for
other threads.getThreadUserTime(long),
isThreadCpuTimeSupported(),
isThreadCpuTimeEnabled(),
setThreadCpuTimeEnabled(boolean)public long getThreadUserTime(long id)
If the thread of the specified ID is not alive or does not exist, this method returns -1. If CPU time measurement is disabled, this method returns -1. A thread is alive if it has been started and has not yet died.
If CPU time measurement is enabled after the thread has started, the Java virtual machine implementation may choose any time up to and including the time that the capability is enabled as the point where CPU time measurement starts.
id - the thread ID of a threadjava.lang.IllegalArgumentException - if id <= 0.java.lang.UnsupportedOperationException - if the Java
virtual machine does not support CPU time measurement for
other threads.getThreadCpuTime(long),
isThreadCpuTimeSupported(),
isThreadCpuTimeEnabled(),
setThreadCpuTimeEnabled(boolean)public boolean isThreadCpuTimeSupported()
public boolean isCurrentThreadCpuTimeSupported()
isThreadCpuTimeSupported()
returns true.public boolean isThreadCpuTimeEnabled()
java.lang.UnsupportedOperationException - if the Java virtual
machine does not support CPU time measurement for other threads
nor for the current thread.isThreadCpuTimeSupported(),
isCurrentThreadCpuTimeSupported()public void setThreadCpuTimeEnabled(boolean enable)
enable - true to enable;
false to disable.java.lang.UnsupportedOperationException - if the Java
virtual machine does not support CPU time measurement for
any threads nor for the current thread.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("control").isThreadCpuTimeSupported(),
isCurrentThreadCpuTimeSupported()public long[] findMonitorDeadlockedThreads()
Object.wait call,
where each thread owns one monitor while
trying to obtain another monitor already held by another thread
in a cycle.
More formally, a thread is monitor deadlocked if it is part of a cycle in the relation "is waiting for an object monitor owned by". In the simplest case, thread A is blocked waiting for a monitor owned by thread B, and thread B is blocked waiting for a monitor owned by thread A.
This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
This method finds deadlocks involving only object monitors.
To find deadlocks involving both object monitors and
ownable synchronizers,
the findDeadlockedThreads method
should be used.
java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").findDeadlockedThreads()public void resetPeakThreadCount()
java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("control").getPeakThreadCount(),
getThreadCount()public long[] findDeadlockedThreads()
This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").java.lang.UnsupportedOperationException - if the Java virtual
machine does not support monitoring of ownable synchronizer usage.isSynchronizerUsageSupported(),
findMonitorDeadlockedThreads()public boolean isObjectMonitorUsageSupported()
dumpAllThreads(boolean, boolean)public boolean isSynchronizerUsageSupported()
dumpAllThreads(boolean, boolean)public java.lang.management.ThreadInfo[] getThreadInfo(long[] ids,
boolean lockedMonitors,
boolean lockedSynchronizers)
This method obtains a snapshot of the thread information for each thread including:
This method returns an array of the ThreadInfo objects, each is the thread information about the thread with the same index as in the ids array. If a thread of the given ID is not alive or does not exist, null will be set in the corresponding element in the returned array. A thread is alive if it has been started and has not yet died.
If a thread does not lock any object monitor or lockedMonitors is false, the returned ThreadInfo object will have an empty MonitorInfo array. Similarly, if a thread does not lock any synchronizer or lockedSynchronizers is false, the returned ThreadInfo object will have an empty LockInfo array.
When both lockedMonitors and lockedSynchronizers parameters are false, it is equivalent to calling:
getThreadInfo(ids, Integer.MAX_VALUE)
This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in the
ThreadInfo.from method.
ids - an array of thread IDs.lockedMonitors - if true, retrieves all locked monitors.lockedSynchronizers - if true, retrieves all locked
ownable synchronizers.ThreadInfo objects, each containing
information about a thread whose ID is in the corresponding
element of the input array of IDs.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").java.lang.UnsupportedOperationException - isObjectMonitorUsageSupported(),
isSynchronizerUsageSupported()public java.lang.management.ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
boolean lockedSynchronizers)
This method returns an array of ThreadInfo objects
as specified in the getThreadInfo(long[], boolean, boolean)
method.
lockedMonitors - if true, dump all locked monitors.lockedSynchronizers - if true, dump all locked
ownable synchronizers.ThreadInfo for all live threads.java.lang.SecurityException - if a security manager
exists and the caller does not have
ManagementPermission("monitor").java.lang.UnsupportedOperationException - isObjectMonitorUsageSupported(),
isSynchronizerUsageSupported()public java.lang.String getName()
public java.lang.String getVmName()
System.getProperty("java.vm.name").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getVmVendor()
System.getProperty("java.vm.vendor").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getVmVersion()
System.getProperty("java.vm.version").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getSpecName()
System.getProperty("java.vm.specification.name").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getSpecVendor()
System.getProperty("java.vm.specification.vendor").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getSpecVersion()
System.getProperty("java.vm.specification.version").java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getManagementSpecVersion()
public java.lang.String getClassPath()
System.getProperty("java.class.path").
Multiple paths in the Java class path are separated by the path separator character of the platform of the Java virtual machine being monitored.
java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public java.lang.String getLibraryPath()
System.getProperty("java.library.path").
Multiple paths in the Java library path are separated by the path separator character of the platform of the Java virtual machine being monitored.
java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to this system property.SecurityManager.checkPropertyAccess(String),
System.getProperty(java.lang.String)public boolean isBootClassPathSupported()
public java.lang.String getBootClassPath()
Multiple paths in the boot class path are separated by the path separator character of the platform on which the Java virtual machine is running.
A Java virtual machine implementation may not support
the boot class path mechanism for the bootstrap class loader
to search for class files.
The isBootClassPathSupported() method can be used
to determine if the Java virtual machine supports this method.
java.lang.UnsupportedOperationException - if the Java virtual machine does not support this operation.java.lang.SecurityException - if a security manager exists and the caller does not have
ManagementPermission("monitor").public java.util.List<java.lang.String> getInputArguments()
Some Java virtual machine implementations may take input arguments from multiple different sources: for examples, arguments passed from the application that launches the Java virtual machine such as the 'java' command, environment variables, configuration files, etc.
Typically, not all command-line options to the 'java' command are passed to the Java virtual machine. Thus, the returned input arguments may not include all command-line options.
MBeanServer access:
The mapped type of List<String> is String[].
java.lang.SecurityException - if a security manager exists and the caller does not have
ManagementPermission("monitor").public long getUptime()
public long getStartTime()
public java.util.Map<java.lang.String,java.lang.String> getSystemProperties()
System.getProperties() to get all
system properties. Properties whose name or value is not
a String are omitted.
MBeanServer access:
The mapped type of Map<String,String> is
TabularData
with two items in each row as follows:
Item Name Item Type key String value String
java.lang.SecurityException - if a security manager exists and its
checkPropertiesAccess method doesn't allow access
to the system properties.