|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.MemoryMeasurer
public class MemoryMeasurer
Class which measures memory state in a JVM.
This class is multithread safe: it is stateless.
Nested Class Summary | |
---|---|
static class |
MemoryMeasurer.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private boolean |
callRestoreJvm
If true, causes getMemoryState to first call restoreJvm before measuring memory. |
private static int |
maxRestoreJvmLoops
Specifies the maximum number of loops that restoreJvm will execute. |
private static long |
pauseTime
Specifies the number of milliseconds that restoreJvm will sleep for between loop iterations. |
Constructor Summary | |
---|---|
MemoryMeasurer()
Calls . |
|
MemoryMeasurer(boolean callRestoreJvm)
Fundamental constructor. |
Method Summary | |
---|---|
MemoryState |
getMemoryState()
Returns a new MemoryState instance which describes the current memory state. |
static long |
memoryUsed()
Returns how much memory on the heap is currently being used. |
static MemoryState |
perform()
Returns . |
static MemoryState |
perform(boolean callRestoreJvm)
Returns new |
static void |
restoreJvm()
Tries to restore the JVM to as clean a state as possible. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int maxRestoreJvmLoops
restoreJvm
will execute.
private static final long pauseTime
restoreJvm
will sleep for between loop iterations.
private final boolean callRestoreJvm
getMemoryState
to first call restoreJvm
before measuring memory.
Constructor Detail |
---|
public MemoryMeasurer()
this
(false)
.
public MemoryMeasurer(boolean callRestoreJvm)
Method Detail |
---|
public static MemoryState perform()
perform
(false)
.
public static MemoryState perform(boolean callRestoreJvm)
new MemoryMeasurer
(callRestoreJvm).getMemoryState
()
.
This is a convenience method for users who just want a few memory measurements.
Users who wish to make many measurements should create a dedicated MemoryMeasurer instance instead.
public static void restoreJvm()
The first technique is a request for object finalizers to run
(via a call to System.runFinalization
).
The second technique is a request for garbage collection to run
(via a call to System.gc
).
These calls are done in a loop that executes at least once,
and at most maxRestoreJvmLoops
times,
but will execute fewer times if no more objects remain to be finalized and heap memory usage becomes constant.
This article suggested the idea to aggressively call for garbage collection many times, and to use heap memory as a metric for deciding when can stop garbage collecting.
public static long memoryUsed()
public MemoryState getMemoryState()
No guarantee can be made regarding the accuracy of the result since it is impossible to get an atomic snapshot of the JVM's memory state. Furthermore, the memory state can change rapidly, so that the result may soon be obsolete.
callRestoreJvm
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |