public class Memory extends java.lang.Object implements RevisionHandler
setEnabled(boolean)| Modifier and Type | Field and Description |
|---|---|
static long |
LOW_MEMORY_MINIMUM |
protected boolean |
m_Enabled
whether memory management is enabled
|
protected static java.lang.management.MemoryMXBean |
m_MemoryMXBean
the managed bean to use
|
protected java.lang.management.MemoryUsage |
m_MemoryUsage
the last MemoryUsage object obtained
|
protected long |
m_SleepTime
the delay before testing for out of memory
|
protected boolean |
m_UseGUI
whether a GUI is present
|
static long |
MAX_SLEEP_TIME |
static long |
OUT_OF_MEMORY_THRESHOLD |
| Constructor and Description |
|---|
Memory()
initializes the memory management without GUI support
|
Memory(boolean useGUI)
initializes the memory management
|
| Modifier and Type | Method and Description |
|---|---|
long |
getCurrent()
returns the currently used size of the JVM heap, obtains a fresh
MemoryUsage object to do so.
|
long |
getInitial()
returns the initial size of the JVM heap, obtains a fresh MemoryUsage
object to do so.
|
long |
getMax()
returns the maximum size of the JVM heap, obtains a fresh MemoryUsage
object to do so.
|
java.lang.String |
getRevision()
Returns the revision string.
|
boolean |
getUseGUI()
whether to display a dialog in case of a problem (= TRUE) or just print on
stderr (= FALSE)
|
boolean |
isEnabled()
returns whether the memory management is enabled
|
boolean |
isOutOfMemory()
checks if there's still enough memory left by checking whether there is
still a 50MB margin between getUsed() and getMax(). if ENABLED is true,
then false is returned always. updates the MemoryUsage variable before
checking.
|
static void |
main(java.lang.String[] args)
prints only some statistics
|
boolean |
memoryIsLow()
Checks to see if memory is running low.
|
void |
setEnabled(boolean value)
sets whether the memory management is enabled
|
boolean |
showMemoryIsLow()
Prints a warning message if memoryIsLow (and if GUI is present a dialog).
|
void |
showOutOfMemory()
prints an error message if OutOfMemory (and if GUI is present a dialog),
otherwise nothing happens. isOutOfMemory() has to be called beforehand,
since it sets all the memory parameters.
|
void |
stopThreads()
stops all the current threads, to make a restart possible
|
static double |
toMegaByte(long bytes)
returns the amount of bytes as MB
|
public static final long OUT_OF_MEMORY_THRESHOLD
public static final long LOW_MEMORY_MINIMUM
public static final long MAX_SLEEP_TIME
protected boolean m_Enabled
protected boolean m_UseGUI
protected static java.lang.management.MemoryMXBean m_MemoryMXBean
protected java.lang.management.MemoryUsage m_MemoryUsage
protected long m_SleepTime
public Memory()
public Memory(boolean useGUI)
useGUI - whether a GUI is presentpublic boolean isEnabled()
public void setEnabled(boolean value)
value - true if the management should be enabledpublic boolean getUseGUI()
public long getInitial()
public long getCurrent()
public long getMax()
public boolean isOutOfMemory()
public boolean memoryIsLow()
public static double toMegaByte(long bytes)
public void showOutOfMemory()
isOutOfMemory(),
m_Enabledpublic boolean showMemoryIsLow()
public void stopThreads()
public java.lang.String getRevision()
getRevision in interface RevisionHandlerpublic static void main(java.lang.String[] args)
args - the commandline arguments - ignored