patterntesting.runtime.monitor
Class MemoryGuard

Package class diagram package MemoryGuard
java.lang.Object
  extended by patterntesting.runtime.monitor.MemoryGuard

public final class MemoryGuard
extends Object

The Class MemoryGuard.

Since:
19.01.2009
Version:
$Revision: 1.8 $
Author:
oliver

Method Summary
static long getFreeMemory()
          Gets the free memory.
static String getFreeMemoryAsString()
          Gets the free memory as string.
static int getFreeMemoryInPercent()
          Gets the free memory in percent.
static 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.slf4j.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 String getFreeMemoryAsString()
Gets the free memory as string.

Returns:
the free memory as string

logMemory

public static void logMemory()
Log memory.

See Also:
logMemory(Logger)

logMemory

public static void logMemory(org.slf4j.Logger lg)
Logs a message if free memory falls down below x% of maximal heap size where x is: .

Parameters:
lg - the log

getMemoryLogMessage

public static String getMemoryLogMessage()
Gets the memory log message.

Returns:
the memory log message

logFreeMemory

public static void logFreeMemory(long interval)
                          throws InterruptedException
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. If there is already a background thread running it will be suspended before a new background thread will be started.

Parameters:
interval - (the sleep intervall in milliseconds, e.g. 300000 for 5 min.)
Throws:
InterruptedException - the interrupted exception


Copyright © 2002–2014 PatternTesting Team. All rights reserved.