info.rolandkrueger.roklib.system
Class MemorySwappingDetectionThread

java.lang.Object
  extended by java.lang.Thread
      extended by info.rolandkrueger.roklib.system.MemorySwappingDetectionThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
VMStatSwappingDetectionThread

public abstract class MemorySwappingDetectionThread
extends Thread

Abstract class for implementations of threads that are able to detect memory paging events on the local system. Subclasses of this class can implement their own specific methods for detecting memory paging by providing an implementation for the abstract method isSwapEventDetected(). This method is repeatedly called during the lifetime of the detection thread.

Author:
Roland Krueger

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  MemorySwappingEventListener mListener
           
private  boolean mStopRequest
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MemorySwappingDetectionThread(MemorySwappingEventListener listener)
          Constructor.
 
Method Summary
protected abstract  boolean isSwapEventDetected()
          Returns true if a memory paging event was detected
protected  void notifyListenerOfSwappingEvent()
          If a swapping event was detected, this method notifies the MemorySwappingEventListener of that.
 void run()
          During its execution, the swapping detection thread will repeatedly call isSwapEventDetected() and check if a swapping event was detected.
 void stopThread()
          Stop this thread.
protected abstract  void stopThreadImpl()
          Implementations of this method define the actions that have to be taken prior to stopping this thread.
 
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

mListener

private MemorySwappingEventListener mListener

mStopRequest

private boolean mStopRequest
Constructor Detail

MemorySwappingDetectionThread

public MemorySwappingDetectionThread(MemorySwappingEventListener listener)
Constructor.

Parameters:
listener - class implementing the MemorySwappingEventListener interface which will be notified of swapping events
Method Detail

isSwapEventDetected

protected abstract boolean isSwapEventDetected()
Returns true if a memory paging event was detected

Returns:
true if a memory paging event was detected

stopThreadImpl

protected abstract void stopThreadImpl()
Implementations of this method define the actions that have to be taken prior to stopping this thread.


run

public void run()
During its execution, the swapping detection thread will repeatedly call isSwapEventDetected() and check if a swapping event was detected. If so, the listener will be notified of this event.

Important: Since isSwapEventDetected() will be called within a loop, you must take care that the implementation of this method will block the thread for a reasonable amount of time (e.g., via Thread.sleep(long). Otherwise this thread will consume too much CPU time through the 'busy wait'.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

notifyListenerOfSwappingEvent

protected void notifyListenerOfSwappingEvent()
If a swapping event was detected, this method notifies the MemorySwappingEventListener of that.


stopThread

public final void stopThread()
Stop this thread.



Copyright © 2007-2011. All Rights Reserved.