public final class Util extends Object
Modifier and Type | Method and Description |
---|---|
static long |
availableMemory()
Returns the amount of available memory (free memory plus never allocated memory).
|
static void |
compactMemory()
Tries to compact memory as much as possible by forcing garbage collection.
|
static void |
ensureLog4JIsConfigured()
Ensures that Log4J is configured, by invoking, if necessary,
BasicConfigurator.configure() , and
setting the root logger level to Level.INFO . |
static void |
ensureLog4JIsConfigured(Class<?> klass)
Ensures that Log4J is configured, by invoking, if necessary,
BasicConfigurator.configure() , and
setting the root logger level to Level.INFO . |
static void |
ensureLog4JIsConfigured(Class<?> klass,
org.apache.log4j.Level level)
Ensures that Log4J is configured, by invoking, if necessary,
BasicConfigurator.configure() , and
setting the root logger level to level . |
static void |
ensureLog4JIsConfigured(org.apache.log4j.Level level)
Ensures that Log4J is configured, by invoking, if necessary,
BasicConfigurator.configure() , and
setting the root logger level to a specified logging level. |
static String |
format(double d)
Formats a number.
|
static String |
format(long l)
Formats a number.
|
static String |
formatBinarySize(long l)
Formats a binary size.
|
static String |
formatSize(long l)
Formats a size.
|
static org.apache.log4j.Logger |
getDebugLogger(Class<?> klass)
Calls Log4J's
Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured() with argument Level.DEBUG . |
static org.apache.log4j.Logger |
getLogger(Class<?> klass)
Calls Log4J's
Logger.getLogger(java.lang.Class) method and then ensureLog4JIsConfigured() . |
static boolean |
log4JIsConfigured()
Checks whether Log4J is properly configuring by searching for appenders in all loggers.
|
static boolean |
memoryIsLow()
Returns true if less then 5% of the available memory is free.
|
static int |
percAvailableMemory()
Returns the percentage of available memory (free memory plus never allocated memory).
|
public static String format(double d)
This method formats a double separating thousands and printing just two fractional digits.
d
- a number.public static String format(long l)
This method formats a long separating thousands.
l
- a number.public static String formatSize(long l)
This method formats a long using suitable unit multipliers (e.g., K, M, G, and T) and printing just two fractional digits.
l
- a number, representing a size (e.g., memory).public static String formatBinarySize(long l)
This method formats a long using suitable unit binary multipliers (e.g., Ki, Mi, Gi, and Ti) and printing no fractional digits. The argument must be a power of 2.
l
- a number, representing a binary size (e.g., memory); must be a power of 2.public static boolean log4JIsConfigured()
public static void ensureLog4JIsConfigured(Class<?> klass)
BasicConfigurator.configure()
, and
setting the root logger level to Level.INFO
.klass
- the calling class (to be shown to the user).public static void ensureLog4JIsConfigured(Class<?> klass, org.apache.log4j.Level level)
BasicConfigurator.configure()
, and
setting the root logger level to level
.klass
- the calling class (to be shown to the user).level
- the required logging level.public static void ensureLog4JIsConfigured()
BasicConfigurator.configure()
, and
setting the root logger level to Level.INFO
.public static void ensureLog4JIsConfigured(org.apache.log4j.Level level)
BasicConfigurator.configure()
, and
setting the root logger level to a specified logging level.level
- the required logging level.public static org.apache.log4j.Logger getLogger(Class<?> klass)
Logger.getLogger(java.lang.Class)
method and then ensureLog4JIsConfigured()
.klass
- a class that will be passed to Logger.getLogger(java.lang.Class)
.Logger.getLogger(java.lang.Class)
.public static org.apache.log4j.Logger getDebugLogger(Class<?> klass)
Logger.getLogger(java.lang.Class)
method and then ensureLog4JIsConfigured()
with argument Level.DEBUG
.klass
- a class that will be passed to Logger.getLogger(java.lang.Class)
.Logger.getLogger(java.lang.Class)
.public static boolean memoryIsLow()
public static long availableMemory()
public static int percAvailableMemory()
public static void compactMemory()
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.