Package com.complexible.common.base
Class Memory
java.lang.Object
com.complexible.common.base.Memory
Utility class for memory related information.
- Since:
- 2.0
- Version:
- 3.1.1
- Author:
- Evren Sirin, Michael Grove
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longThe number of bytes in a gigabyte (2^30).static final longThe number of bytes in a kilobyte (2^10).static final longThe number of bytes in a kilobyte (2^20). -
Method Summary
Modifier and TypeMethodDescriptionstatic longReturns the current amount of memory available on the heap.static StringDetailed memory information logged only at TRACE level.static longfromReadable(String theStr) Take a representation fromreadable(long)and turn it back into bytes.static Stringstatic longmax()Returns the maximum amount of memory that the JVM will attempt to use.static Stringreadable(long bytes) Returns a human-readable representation of bytes similar to how "ls -h" works in Unix systems.static longReturns the size of this object (with its references).static longsystem()Return the total memory available to the system, ie how much RAM the computer has.static longtotal()Returns the total memory available to JVM in bytes.static longused()Returns the used memory in bytes.static longusedHeap()static longstatic float
-
Field Details
-
KB
public static final long KBThe number of bytes in a kilobyte (2^10).- See Also:
-
MB
public static final long MBThe number of bytes in a kilobyte (2^20).- See Also:
-
GB
public static final long GBThe number of bytes in a gigabyte (2^30).- See Also:
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZE- See Also:
-
-
Method Details
-
readable
Returns a human-readable representation of bytes similar to how "ls -h" works in Unix systems. The resulting is guaranteed to be 4 characters or less unless the given value is greater than 999TB. The last character in the returned string is one of 'B', 'K', 'M', 'G', or 'T' representing bytes, kilobytes, megabytes, gigabytes or terabytes. This function uses the binary unit system where 1K = 1024B.Examples:
482 = 482B 1245 = 1.2K 126976 = 124K 4089471 = 3.9M 43316209 = 41M 1987357695 = 1.9G -
fromReadable
Take a representation fromreadable(long)and turn it back into bytes. For example, if the input is "2K" the output would be 2048.- Parameters:
theStr- the byte string- Returns:
- the number of bytes
-
used
public static long used()Returns the used memory in bytes. The result is an estimate and based on when the GC runs this value might change significantly. -
total
public static long total()Returns the total memory available to JVM in bytes. This value may change over time. -
max
public static long max()Returns the maximum amount of memory that the JVM will attempt to use. It is possible that -
available
public static long available()Returns the current amount of memory available on the heap. Shorthand for:Memory.max() - Memory.used()- Returns:
- available heap memory
-
system
public static long system()Return the total memory available to the system, ie how much RAM the computer has.- Returns:
- the system memory.
-
usedRatio
public static float usedRatio() -
usedHeap
public static long usedHeap() -
usedNonHeap
public static long usedNonHeap() -
heapUsage
-
detailedUsage
Detailed memory information logged only at TRACE level. -
sizeOf
Returns the size of this object (with its references).
-