Class MemoryQuota


  • public class MemoryQuota
    extends Object
    Estimates the amount of memory in the running JVM for use of long term caches by looking at the Old Generation, where implemented, or at the Runtime information as fallback. Allows for reserving memory to avoid over commitment. There is a fudge factor involved, so it is not byte exact.
    • Constructor Detail

      • MemoryQuota

        public MemoryQuota()
        Returns the memory quota reservation system for this server instance.
    • Method Detail

      • getReservableMemory

        public long getReservableMemory()
        Returns the amount of reservable memory in bytes.
        Returns:
        The amount of reservable memory in bytes.
      • isMemoryAvailable

        public boolean isMemoryAvailable​(long sizeInBytes)
        Check enough memory is available in the reservable pool.
        Parameters:
        sizeInBytes - the amount of requested memory (in bytes)
        Returns:
        true if enough memory is available in the reservable pool
      • acquireMemory

        public boolean acquireMemory​(long sizeInBytes)
        Reserves the requested amount of memory in OldGen.
        Parameters:
        sizeInBytes - the requested amount of memory (in bytes)
        Returns:
        true if the requested amount of memory in OldGen could be reserved
      • getAvailableMemory

        public long getAvailableMemory()
        Returns how much memory is currently not reserved (free) in OldGen (in bytes).
        Returns:
        how much memory is currently not reserved (free) in OldGen (in bytes)
      • memBytesToPercent

        public int memBytesToPercent​(long sizeInBytes)
        Translates bytes to percent of reservable memory.
        Parameters:
        sizeInBytes - the amount of memory (in bytes)
        Returns:
        percent of reservable memory
      • memPercentToBytes

        public long memPercentToBytes​(int percent)
        Translates a percentage of reservable memory to the equivalent number of bytes.
        Parameters:
        percent - a percentage of reservable memory
        Returns:
        the equivalent number of bytes
      • releaseMemory

        public void releaseMemory​(long sizeInBytes)
        Declares OldGen memory is not needed anymore.
        Parameters:
        sizeInBytes - the amount of memory to return (in bytes)