public static class MemoryMonitor.PeakMemoryMonitor
extends java.lang.Object
implements java.lang.Runnable
PeakMemoryMonitor
as
Thread monitor = new Thread(new PeakMemoryMonitor());
monitor.start()
and then when you want to stop monitoring, call
monitor.interrupt();
monitor.join();
You only need the last line if you want to be sure the monitor stops before
you move on in the code; and strictly speaking, you should surround the
monitor.join()
call with a try/catch
block, as
the Thread
you are running could itself be interrupted, so you
should actually have something like
monitor.interrupt();
try {
monitor.join();
} catch (InterruptedException ex) {
// handle the exception
}
or else throw the exception.Constructor and Description |
---|
PeakMemoryMonitor() |
PeakMemoryMonitor(int pollFrequency,
int logFrequency) |
PeakMemoryMonitor(int pollFrequency,
int logFrequency,
java.io.PrintStream out) |
Modifier and Type | Method and Description |
---|---|
void |
log() |
void |
run() |
public PeakMemoryMonitor()
public PeakMemoryMonitor(int pollFrequency, int logFrequency)
pollFrequency
- frequency, in milliseconds, with which to polllogFrequency
- frequency, in milliseconds, with which to log maximum memory
used so farpublic PeakMemoryMonitor(int pollFrequency, int logFrequency, java.io.PrintStream out)