Class MemoryQuota


  • public final 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

      • getMaxMemory

        public long getMaxMemory()
        Returns the maximum amount of memory the server will use when giving quotas.
        Returns:
        the maximum amount of memory the server will use when giving quotas
      • isMemoryAvailable

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

        public boolean acquireMemory​(long size)
        Reserves the requested amount of memory in OldGen.
        Parameters:
        size - 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.
        Returns:
        how much memory is currently not reserved (free) in OldGen
      • memBytesToPercent

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

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

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