com.iparelan.util
Class MemoryMonitor

java.lang.Object
  extended by java.lang.Thread
      extended by com.iparelan.util.MemoryMonitor
All Implemented Interfaces:
Runnable

@ThreadSafe
@Immutable
@Copyright(value="Copyright © 2008, Iparelan Solutions, LLC. All rights reserved.")
public final class MemoryMonitor
extends Thread

A thread that monitors the JVM heap.

Version:
July 2008
Author:
Greg Mattes

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
static long BYTES_PER_MEGABYTE
           
static long DEFAULT_FREQUENCY
           
private  long frequency
           
private static RangeValidationStrategy<Long> FREQUENCY_VALIDATOR
           
private static Logger LOGGER
           
static String MEMORY_MONITOR_LOGGER_NAME
           
static long MILLISECONDS_PER_SECOND
           
static long MINIMUM_FREQUENCY
           
private static String NAME
           
static long ONE_SECOND
           
static long THIRTY_SECONDS
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private MemoryMonitor()
          Creates a MemoryMonitor.
private MemoryMonitor(long frequency)
          Creates a MemoryMonitor.
 
Method Summary
 long getFrequency()
          Produces the interval between subsequent memory statistics polling operations, in milliseconds.
static MemoryMonitor newInstance()
          Produces a new MemoryMonitor.
static MemoryMonitor newInstance(long frequency)
          Produces a new MemoryMonitor with the specified polling frequency.
 void run()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

private static final String NAME

MEMORY_MONITOR_LOGGER_NAME

public static final String MEMORY_MONITOR_LOGGER_NAME
See Also:
Constant Field Values

LOGGER

private static final Logger LOGGER

THIRTY_SECONDS

public static final long THIRTY_SECONDS
See Also:
Constant Field Values

ONE_SECOND

public static final long ONE_SECOND
See Also:
Constant Field Values

DEFAULT_FREQUENCY

public static final long DEFAULT_FREQUENCY
See Also:
Constant Field Values

MINIMUM_FREQUENCY

public static final long MINIMUM_FREQUENCY
See Also:
Constant Field Values

BYTES_PER_MEGABYTE

public static final long BYTES_PER_MEGABYTE
See Also:
Constant Field Values

MILLISECONDS_PER_SECOND

public static final long MILLISECONDS_PER_SECOND
See Also:
Constant Field Values

FREQUENCY_VALIDATOR

private static final RangeValidationStrategy<Long> FREQUENCY_VALIDATOR

frequency

private final long frequency
See Also:
getFrequency()
Constructor Detail

MemoryMonitor

private MemoryMonitor()
Creates a MemoryMonitor.


MemoryMonitor

private MemoryMonitor(long frequency)
Creates a MemoryMonitor.

Parameters:
frequency - Memory statistics polling interval.
Throws:
ValidationException - Iff frequency is invalid. See getFrequency() for the meaning "invalid frequency."
See Also:
getFrequency()
Method Detail

newInstance

public static MemoryMonitor newInstance()
Produces a new MemoryMonitor.

Returns:
A new MemoryMonitor.

newInstance

public static MemoryMonitor newInstance(long frequency)
Produces a new MemoryMonitor with the specified polling frequency.

Returns:
A new MemoryMonitor with the specified polling frequency.

getFrequency

public long getFrequency()
Produces the interval between subsequent memory statistics polling operations, in milliseconds. Must be greater than MINIMUM_FREQUENCY: 1000L milliseconds. A default value of 30000L milliseconds is used if no frequency is explicitly specified.

Returns:
The interval between subsequent memory statistics polling operations, in milliseconds.

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread


Copyright © 2008 Iparelan Solutions, LLC. All rights reserved.