Class MemoryGuard


  • public final class MemoryGuard
    extends java.lang.Object
    The Class MemoryGuard.
    Since:
    19.01.2009
    Version:
    $Revision: 1.16 $
    Author:
    oliver
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long getFreeMemory()
      Gets the free memory.
      static java.lang.String getFreeMemoryAsString()
      Gets the free memory as string.
      static int getFreeMemoryInPercent()
      Gets the free memory in percent.
      static java.lang.String getMemoryLogMessage()
      Gets the memory log message.
      static void logFreeMemory​(long interval)
      Every x milliseconds the free memory is checked and printed into the log (according the log level).
      static void logMemory()
      Log memory.
      static void logMemory​(org.apache.logging.log4j.Logger lg)
      Logs a message if free memory falls down below x% of maximal heap size where x is: x < 1%: logs a fatal message 1% <= x < 2%: logs an error 1% <= x < 10%: logs a warning 10% <= x < 20%: logs an info message 20% <= x < 50%: logs debug message x >= 50%: tracing
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getFreeMemory

        public static long getFreeMemory()
        Gets the free memory.
        Returns:
        the free memory
      • getFreeMemoryInPercent

        public static int getFreeMemoryInPercent()
        Gets the free memory in percent.
        Returns:
        the free memory in percent
      • getFreeMemoryAsString

        public static java.lang.String getFreeMemoryAsString()
        Gets the free memory as string.
        Returns:
        the free memory as string
      • logMemory

        public static void logMemory​(org.apache.logging.log4j.Logger lg)
        Logs a message if free memory falls down below x% of maximal heap size where x is:
        • x < 1%: logs a fatal message
        • 1% <= x < 2%: logs an error
        • 1% <= x < 10%: logs a warning
        • 10% <= x < 20%: logs an info message
        • 20% <= x < 50%: logs debug message
        • x >= 50%: tracing
        Parameters:
        lg - the log
      • getMemoryLogMessage

        public static java.lang.String getMemoryLogMessage()
        Gets the memory log message.
        Returns:
        the memory log message
      • logFreeMemory

        public static void logFreeMemory​(long interval)
        Every x milliseconds the free memory is checked and printed into the log (according the log level). This is done with in a separated background thread. You can only start the background logging if you set the log level of this class to DEBUG. To stop the background logging set the interval to 0.
        Parameters:
        interval - (the sleep intervall in milliseconds, e.g. 300000 for 5 min.)