|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.MemoryState
public class MemoryState
Class which records data describing the memory state of a JVM.
This class is multithread safe: it is mostly immutable (both its immediate state, as well as the deep state of its fields).
The sole exception is the integerFormat
field, which is guarded by synchronization.
Nested Class Summary | |
---|---|
static class |
MemoryState.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private long |
available
Amount of memory (within the max allocatable) that could be allocated. |
private long |
free
Amount of memory (within the total allocated) that is free. |
private static DecimalFormat |
integerFormat
|
private long |
max
Maximum amount of memory that could be used by the JVM. |
static String |
separatorDefault
Default value for the separator arg of toStringHeader(String) /toString(String, boolean) . |
private long |
total
Total amount of memory currently used by the JVM. |
private long |
used
Amount of memory (within the total allocated) that is used. |
Constructor Summary | |
---|---|
MemoryState(long free,
long total,
long max)
Constructor. |
Method Summary | |
---|---|
boolean |
equals(Object obj)
Determines equality based on whether or not obj is a MemoryState instance whose every field equals that of this instance. |
private static String |
format(long value)
Returns integerFormat . |
long |
getAvailable()
Returns the value of the available field. |
double |
getAvailableRatio()
Returns the ratio of the available field to the max field. |
long |
getFree()
Returns the value of the free field. |
long |
getMax()
Returns the value of the max field. |
long |
getTotal()
Returns the value of the total field. |
long |
getUsed()
Returns the value of the used field. |
double |
getUsedRatio()
Returns the ratio of the used field to the max field. |
int |
hashCode()
Returns a value based on all of the fields. |
static MemoryState |
parse(String s,
String separator)
Parse a new MemoryState instance from the data in s. |
String |
toString()
Returns . |
String |
toString(String separator,
boolean includeLabels)
Returns a String which describes this instance. |
static String |
toStringHeader()
Returns . |
static String |
toStringHeader(String separator)
Returns a description of the data returned by toString(String, boolean) . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String separatorDefault
toStringHeader(String)
/toString(String, boolean)
.
private static final DecimalFormat integerFormat
private final long used
Contract: is >= 0, and is always equal to total
- free
private final long free
Runtime.freeMemory()
.
Contract: is >= 0, and is always equal to total
- used
private final long available
Contract: is >= 0, and is always equal to max
- used
private final long total
Runtime.totalMemory()
.
Contract: is >= 1, and is always equal to used
+ free
private final long max
Runtime.maxMemory()
.
Contract: is >= 1, and is always equal to used
+ available
Constructor Detail |
---|
public MemoryState(long free, long total, long max) throws IllegalArgumentException
IllegalArgumentException
- if free < 0; total < 1; max < 1Method Detail |
---|
private static String format(long value)
integerFormat
.format
(value).
public static MemoryState parse(String s, String separator) throws IllegalArgumentException
Warning: separator will be directly supplied as the regex argument to String.split, so you must ensure that it is a valid regex and will split the tokens of s as expected. In particular, if s has field labels inside it, you will need to write a complicated regex to handle that, as opposed to a simple regex like ", " or "\\t" for bare comma and tab delimted data.
IllegalArgumentException
- if s is blank; separator == null;
s does not obey the expected format for a legitimate MemoryState representationpublic long getUsed()
used
field.
public double getUsedRatio()
used
field to the max
field.
In other words, this method returns the relative amount of memory being used.
public long getFree()
free
field.
public long getAvailable()
available
field.
public double getAvailableRatio()
available
field to the max
field.
In other words, this method returns the relative amount of memory that still could be allocated
given the memory that is already being used.
public long getTotal()
total
field.
public long getMax()
max
field.
public final boolean equals(Object obj)
equals
in class Object
public final int hashCode()
hashCode
in class Object
public static String toStringHeader()
toStringHeader
(separatorDefault
)
.
public static String toStringHeader(String separator) throws IllegalArgumentException
toString(String, boolean)
.
IllegalArgumentException
- if separator == null or separator.length() == 0public String toString()
toString
(separatorDefault
, true)
.
toString
in class Object
public String toString(String separator, boolean includeLabels) throws IllegalArgumentException
separator
- String value to place between the different memory types in order to separate themincludeLabels
- specifies whether or not to label the different memory types
IllegalArgumentException
- if separator == null or separator.length() == 0
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |