Class RuntimeMemoryChecker

  • All Implemented Interfaces:
    MemoryChecker

    public class RuntimeMemoryChecker
    extends java.lang.Object
    implements MemoryChecker
    A memory checker that uses the Java Runtime instance to check the amount of available memory. A given amount of memory must be kept free, however, this condition is only signalled if a given percentage of the JVM's potential memory usage has been exhausted.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.slf4j.Logger logger
      the logger for this class
      protected static java.lang.Runtime runtime
      JVM runtime
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkMemory()
      Returns true if memory is running low.
      void reset()
      Reset the out of memory flag
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
        the logger for this class
      • runtime

        protected static final java.lang.Runtime runtime
        JVM runtime
    • Constructor Detail

      • RuntimeMemoryChecker

        public RuntimeMemoryChecker()
        Default constructor. Uses ApplicationSetup.MEMORY_THRESHOLD_SINGLEPASS and memory.heap.usage for the default memory threshold amount (default 0.70).
      • RuntimeMemoryChecker

        public RuntimeMemoryChecker​(long _reserved,
                                    double _threshold)
        Construct a RuntimeMemoryChecker.
        Parameters:
        _reserved - The amount of memory that must be kept available.
        _threshold - Percentage of possible memory that must be allocated before a lowMemory condition is allowed.
    • Method Detail

      • checkMemory

        public boolean checkMemory()
        Returns true if memory is running low. If this returns true, it will continue to do so until reset() is called, which the client code should do once memory has been freed.
        Specified by:
        checkMemory in interface MemoryChecker
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • reset

        public void reset()
        Reset the out of memory flag
        Specified by:
        reset in interface MemoryChecker