public class FauxMemoryMonitor extends Object implements MemoryMonitor
FauxMemoryMonitor
implements the MemoryMonitor
interface but does nothing: all methods are empty.MemoryMonitor.Listener, MemoryMonitor.Test
Modifier and Type | Method and Description |
---|---|
boolean |
addListener(MemoryMonitor.Listener listener)
Adds a
Listener using the default threshold percentage. |
boolean |
addListener(MemoryMonitor.Listener listener,
int thresholdPercentage)
Adds a
Listener to the MemoryMonitor with
a given threshold percentage. |
long |
getMaxMemory()
Returns the maximum memory usage.
|
long |
getUsedMemory()
Returns the current memory used.
|
void |
removeAllListener()
Clear out all
Listener s and turnoff JVM
memory notification. |
boolean |
removeListener(MemoryMonitor.Listener listener)
Removes a
Listener from the MemoryMonitor . |
void |
updateListenerThreshold(MemoryMonitor.Listener listener,
int percentage)
Changes the threshold percentage of a given
Listener . |
public boolean addListener(MemoryMonitor.Listener listener, int thresholdPercentage)
MemoryMonitor
Listener
to the MemoryMonitor
with
a given threshold percentage.
If the threshold is below the Java5 memory managment system's threshold, then the Listener is notified from within this method.
addListener
in interface MemoryMonitor
listener
- the Listener
to be added.thresholdPercentage
- the threshold percentage for this
Listener
.true
if the Listener
was
added and false
otherwise.public boolean addListener(MemoryMonitor.Listener listener)
MemoryMonitor
Listener
using the default threshold percentage.
If the threshold is below the Java5 memory managment system's threshold, then the Listener is notified from within this method.
addListener
in interface MemoryMonitor
listener
- the Listener
to be added.true
if the Listener
was
added and false
otherwise.public void updateListenerThreshold(MemoryMonitor.Listener listener, int percentage)
MemoryMonitor
Listener
.
If the new value is below the system's current value, then the
Listener
will have its notification callback called
while in this method - so a client should always check if its
notification method was called immediately after calling this
method.
This method can be used if, for example, an algorithm has different approaches that result in different memory usage profiles; one, large memory but fast and a second which is low-memory but slow. The algorithm starts with the large memory approach, receives a low memory notification, switches to the low memory approach and changes when it should be notified for this new approach. The first approach need to be notified at a lower percentage because it uses lots of memory, possibly quickly; while the second approach, possibly a file based algorithm, has smaller memory requirements and uses memory less quickly thus one can live with a higher notification threshold percentage.
updateListenerThreshold
in interface MemoryMonitor
listener
- the Listener
being updated.percentage
- new percentage threshold.public boolean removeListener(MemoryMonitor.Listener listener)
MemoryMonitor
Listener
from the MemoryMonitor
.
Returns true
if listener was removed and
false
otherwise.removeListener
in interface MemoryMonitor
listener
- the listener to be removedtrue
if listener was removed.public void removeAllListener()
MemoryMonitor
Listener
s and turnoff JVM
memory notification.removeAllListener
in interface MemoryMonitor
public long getMaxMemory()
MemoryMonitor
getMaxMemory
in interface MemoryMonitor
public long getUsedMemory()
MemoryMonitor
getUsedMemory
in interface MemoryMonitor
Copyright © 2020 Hitachi Vantara. All rights reserved.