Class MBeanUtilities
Supported API: true
Extendable: false
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanValue of THREAD_MBEAN.isCurrentThreadCpuTimeSupported().static final booleanValue of THREAD_MBEAN.isThreadCpuTimeSupported().static final OperatingSystemMXBeanPlatform OperatingSystemMXBean (result ofManagementFactory.getOperatingSystemMXBean())
Supported API: truestatic final RuntimeMXBeanstatic final booleanValue of THREAD_MBEAN.isThreadContentionMonitoringSupported().static final ThreadMXBeanstatic final longJava virtual machine start time (result of RUNTIME_MBEAN.getStartTime())
Supported API: true -
Method Summary
Modifier and TypeMethodDescriptionstatic MBeanInfofixOpenMBeanAttrInfo(MBeanInfo origMBeanInfo, Map<String, ? extends OpenType> attrNameToTypeMap) Returns updated version of the MBeanInfo provided wherein the MBeanAttributeInfo for each attribute named in the given map is replaced by an OpenMBeanAttributeInfo that is identical except that corresponding OpenType from the map is specified as the return type.static StringformatMessage(String messageFormat, Object... formatArgs) Localized (and simplified) replacement forWTMessageto avoid this dependency in lower-level MBean code.static intReturns the available number of processors.static long[]Return ids of threads which are currently deadlocked or null if there are currently no deadlocked threads.static String[]Get full stack trace (from THREAD_MBEAN) as an array of Strings.static intgetInitialHashCapacity(int initialElementCount, float loadFactor) Compute actual initial size of hash map/set needed to ensure no rehashing is done for the specified initial element count
Supported API: truestatic longgetMilliTimeFromNanoTime(long nanoTime) Deprecated.static longgetNanoTimeFromMilliTime(long milliTime) Deprecated.static longGet a (per instance of this class) unique sequence number specifically for use in giving ids to notifications.static longReturns CPU time consumed by process since startup in nanosecond precision (but not necessarily nanosecond accuracy).static CompositeData[]getSortedData(TabularData tabularData) Sorts the given TabularData's CompositeData by field specified as TabularData's indexing keys and returns the CompositeData objects as an array.static longgetThreadAllocatedBytes(long threadId) Where possible returns the estimated number of bytes allocated by the given thread.static long[]getThreadAllocatedBytes(long[] threadIds) Where possible returns the estimated number of bytes allocated by each of the specified threads.static long[]getThreadCpuTimes(long[] threadIds) Returns CPU times for each of the specified threads.static String[]getThreadInfoAsStringArray(long threadId) Gets full single thread info (including stack trace) as a String array
Supported API: truestatic String[]getThreadInfoAsStringArray(long threadId, Thread thread) Gets full single thread info (including stack trace) as a String array; if 'thread' is non-null it is used to provide additional information
Supported API: truestatic String[]getThreadInfoAsStringArray(Thread thread) Gets full single thread info (including stack trace) as a String array
Supported API: truestatic long[]getThreadUserTimes(long[] threadIds) Returns user times for each of the specified threads.static booleanEncapsulates calls to THREAD_MBEAN.isThreadCpuTimeEnabled().static <K,V> HashMap <K, V> newHashMap(int initialElementCount, float loadFactor) Produces a HashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: truestatic <T> HashSet<T> newHashSet(int initialElementCount, float loadFactor) Produces a HashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: truestatic <K,V> LinkedHashMap <K, V> newLinkedHashMap(int initialElementCount, float loadFactor) Produces a LinkedHashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: truestatic <T> HashSet<T> newLinkedHashSet(int initialElementCount, float loadFactor) Produces a LinkedHashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: truestatic TabularDataSupportnewTabularDataSupport(TabularType tabularType, int initialElementCount, float loadFactor) Produces TabularDataSupport object of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: truestatic StringrenderAsTimestampPlusTimeZone(Date timestamp) Render as with Timestamp.toString() plus 4 digit RFC 822 time zone specification.
-
Field Details
-
THREAD_MBEAN
-
RUNTIME_MBEAN
-
OS_MBEAN
Platform OperatingSystemMXBean (result ofManagementFactory.getOperatingSystemMXBean())
Supported API: true -
VM_START_TIME
public static final long VM_START_TIMEJava virtual machine start time (result of RUNTIME_MBEAN.getStartTime())
Supported API: true -
CURRENT_THREAD_CPU_TIME_SUPPORTED
public static final boolean CURRENT_THREAD_CPU_TIME_SUPPORTEDValue of THREAD_MBEAN.isCurrentThreadCpuTimeSupported().
Supported API: true -
NON_CURRENT_THREAD_CPU_TIME_SUPPORTED
public static final boolean NON_CURRENT_THREAD_CPU_TIME_SUPPORTEDValue of THREAD_MBEAN.isThreadCpuTimeSupported().
Supported API: true -
THREAD_CONTENTION_MONITORING_SUPPORTED
public static final boolean THREAD_CONTENTION_MONITORING_SUPPORTEDValue of THREAD_MBEAN.isThreadContentionMonitoringSupported().
Supported API: true
-
-
Method Details
-
getNotificationSequenceNumber
public static long getNotificationSequenceNumber()Get a (per instance of this class) unique sequence number specifically for use in giving ids to notifications.
Supported API: true -
getProcessCpuTime
public static long getProcessCpuTime()Returns CPU time consumed by process since startup in nanosecond precision (but not necessarily nanosecond accuracy).Note that this method assumes that the ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME has an attribute named "ProcessCpuTime" containing this information, which is the case in Sun JVMs. If such an attribute is not found, then this method will simply return 0.
Supported API: true -
getAvailableProcessors
public static int getAvailableProcessors()Returns the available number of processors. This is essentially a shortcut for Runtime.getRuntime().availableProcessors().
Supported API: true -
getDeadlockedThreadIds
public static long[] getDeadlockedThreadIds()Return ids of threads which are currently deadlocked or null if there are currently no deadlocked threads.
Supported API: true -
getFullStackTraceAsStringArray
Get full stack trace (from THREAD_MBEAN) as an array of Strings.
Supported API: true -
getThreadAllocatedBytes
public static long getThreadAllocatedBytes(long threadId) Where possible returns the estimated number of bytes allocated by the given thread. This functionality is currently specific to the Oracle HotSpot JVM and Java 6 Update 25 or higher. Where this is not possible, this method returns -1.
Supported API: true -
getThreadAllocatedBytes
public static long[] getThreadAllocatedBytes(long[] threadIds) Where possible returns the estimated number of bytes allocated by each of the specified threads. This functionality is currently specific to the Oracle HotSpot JVM and Java 6 Update 25 or higher. Where this is not possible, this method returns null.
Supported API: true -
getThreadCpuTimes
public static long[] getThreadCpuTimes(long[] threadIds) Returns CPU times for each of the specified threads. This method does not check if thread CPU time monitoring is supported and enabled, that is the caller's responsibility in this case.
Supported API: true -
getThreadUserTimes
public static long[] getThreadUserTimes(long[] threadIds) Returns user times for each of the specified threads. This method does not check if thread CPU time monitoring is supported and enabled, that is the caller's responsibility in this case.
Supported API: true -
getThreadInfoAsStringArray
Gets full single thread info (including stack trace) as a String array
Supported API: true -
getThreadInfoAsStringArray
Gets full single thread info (including stack trace) as a String array
Supported API: true -
getThreadInfoAsStringArray
Gets full single thread info (including stack trace) as a String array; if 'thread' is non-null it is used to provide additional information
Supported API: true -
renderAsTimestampPlusTimeZone
Render as with Timestamp.toString() plus 4 digit RFC 822 time zone specification.
Supported API: true -
formatMessage
Localized (and simplified) replacement forWTMessageto avoid this dependency in lower-level MBean code. This routine should be used instead of directly usingMessageFormatto provide easier handling of quote characters for localizers.
Supported API: true -
getMilliTimeFromNanoTime
Deprecated.Convert from a System.nanoTime() results to an approximate System.currentTimeMillis() result. Note that this is not simply the input divided by 1000000L (do that yourself as needed to convert from an elapsed nanosecond to millisecond time). Rather this handles the offset between System.nanoTime() and System.currentTimeMillis() results so that the result of this routine can be used in constructing Dates, Timestamps, etc.This method is now deprecated because any manual or automatic change to the system clock during application execution will alter the offset between these timers and thus introduce error in the conversion.
Supported API: true -
getNanoTimeFromMilliTime
Deprecated.Inverse operation of getMilliTimeFromNanoTime().This method is now deprecated because any manual or automatic change to the system clock during application execution will alter the offset between these timers and thus introduce error in the conversion.
Supported API: true -
getSortedData
Sorts the given TabularData's CompositeData by field specified as TabularData's indexing keys and returns the CompositeData objects as an array.The CompositeData within a TabularData are naturally in hash order, so this utility is necessary when a human-meaningful ordering is desired.
Supported API: true -
fixOpenMBeanAttrInfo
public static MBeanInfo fixOpenMBeanAttrInfo(MBeanInfo origMBeanInfo, Map<String, ? extends OpenType> attrNameToTypeMap) Returns updated version of the MBeanInfo provided wherein the MBeanAttributeInfo for each attribute named in the given map is replaced by an OpenMBeanAttributeInfo that is identical except that corresponding OpenType from the map is specified as the return type.This is the correct thing to do when for attributes returning TabularData or CompositeData in that this allows JMX applications to programmatically determine the precise data type that will be returned without / prior to fetching a value. It seems that most JMX consoles do not require this level of precision, however, so this is not strictly necessary.
Supported API: true- Parameters:
origMBeanInfo- Original MBeanInfo objectattrNameToTypeMap- Map from attribute names to corresponding OpenTypes- Returns:
- Augmented/updated MBeanInfo
-
isThreadCpuTimeEnabled
public static boolean isThreadCpuTimeEnabled()Encapsulates calls to THREAD_MBEAN.isThreadCpuTimeEnabled(). This allows us to work around issues in some JVMs wherein an UnsupportedOperationException is thrown even though isCurrentThreadCpuTimeSupported() returns true! This is done by returning catching UnsupportedOperationExceptions and returning false in such cases.One should check CURRENT_THREAD_CPU_TIME_SUPPORTED and/or NON_CURRENT_THREAD_CPU_TIME_SUPPORTED prior to calling this method despite its internal workaround to save the overhead of unnecessary exception throws.
Supported API: true -
newHashMap
Produces a HashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: true -
newLinkedHashMap
Produces a LinkedHashMap of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: true -
newHashSet
Produces a HashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: true -
newLinkedHashSet
Produces a LinkedHashSet of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: true -
newTabularDataSupport
public static TabularDataSupport newTabularDataSupport(TabularType tabularType, int initialElementCount, float loadFactor) Produces TabularDataSupport object of an appropriate actual initial size to hold initialElementCount elements without rehashing
Supported API: true -
getInitialHashCapacity
public static int getInitialHashCapacity(int initialElementCount, float loadFactor) Compute actual initial size of hash map/set needed to ensure no rehashing is done for the specified initial element count
Supported API: true
-