info.rolandkrueger.roklib.system
Class VMStatSwappingDetectionThread
java.lang.Object
java.lang.Thread
info.rolandkrueger.roklib.system.MemorySwappingDetectionThread
info.rolandkrueger.roklib.system.VMStatSwappingDetectionThread
- All Implemented Interfaces:
- Runnable
public class VMStatSwappingDetectionThread
- extends MemorySwappingDetectionThread
This class is a concrete implementation of the abstract class
MemorySwappingDetectionThread
where the program vmstat
is used for detecting memory swapping. When the thread is started,
vmstat
is invoked with an update delay of a configurable number
of seconds. The thread will then evaluate the output of vmstat
upon each update. If the swap in/out column of vmstat
's output
differs from 0 the object registered as MemorySwappingEventListener
will be notified of that event.
Note: Detecting memory paging with an external, platform-dependent tool such
as vmstat
is of course detrimental to the application's
portability. This strategy was chosen, though, since it offered an easy to
implement method for swapping detection. Unfortunately, the Java language as
yet doesn't offer any general machanisms to detect these memory paging
situations in a portable way. If there are any better ways to cope with that
in the future, an appropriate method can be implemented as a subclass of
MemorySwappingDetectionThread
.
- Author:
- Roland Krueger
Method Summary |
protected boolean |
isSwapEventDetected()
Returns true if a memory paging event was detected |
boolean |
startProcess()
Starts the vmstat command in an own process. |
protected 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 |
sLogger
protected static Logger sLogger
CMD_STRING
private static final String CMD_STRING
- See Also:
- Constant Field Values
SWAP_PATTERN
private static final Pattern SWAP_PATTERN
- Regular expression that extracts the swap in and swap out columns of the
vmstat
output.
mVMStatBinaryLocation
private String mVMStatBinaryLocation
mSamplingRate
private int mSamplingRate
mVMStatProcess
private Process mVMStatProcess
mProcessReader
private BufferedReader mProcessReader
mLine
private String mLine
mMatcher
private Matcher mMatcher
VMStatSwappingDetectionThread
public VMStatSwappingDetectionThread(MemorySwappingEventListener listener,
String vmstatBinaryLocation,
int samplingRate)
- Constructor.
- Parameters:
listener
- object that implements the MemorySwappingEventListener
interfacevmstatBinaryLocation
- the location of the vmstat
command. This is usually
/usr/bin/vmstat
.samplingRate
- the update delay for vmstat
startProcess
public boolean startProcess()
- Starts the
vmstat
command in an own process.
- Returns:
true
if the process was successfully started
isSwapEventDetected
protected boolean isSwapEventDetected()
- Description copied from class:
MemorySwappingDetectionThread
- Returns
true
if a memory paging event was detected
- Specified by:
isSwapEventDetected
in class MemorySwappingDetectionThread
- Returns:
true
if a memory paging event was detected
stopThreadImpl
protected void stopThreadImpl()
- Description copied from class:
MemorySwappingDetectionThread
- Implementations of this method define the actions that have to be taken
prior to stopping this thread.
- Specified by:
stopThreadImpl
in class MemorySwappingDetectionThread
Copyright © 2007-2011. All Rights Reserved.