Add SystemPropertyUtil.refresh()
This commit is contained in:
parent
5a9d6e59c1
commit
21c9c26ff8
@ -25,25 +25,34 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public final class SystemPropertyUtil {
|
public final class SystemPropertyUtil {
|
||||||
|
|
||||||
private static final InternalLogger logger =
|
private static final Properties props = new Properties();
|
||||||
InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
|
private static final InternalLogger logger;
|
||||||
|
|
||||||
private static final Properties props;
|
|
||||||
|
|
||||||
// Retrieve all system properties at once so that there's no need to deal with
|
// Retrieve all system properties at once so that there's no need to deal with
|
||||||
// security exceptions from next time. Otherwise, we might end up with logging every
|
// security exceptions from next time. Otherwise, we might end up with logging every
|
||||||
// security exceptions on every system property access or introducing more complexity
|
// security exceptions on every system property access or introducing more complexity
|
||||||
// just because of less verbose logging.
|
// just because of less verbose logging.
|
||||||
static {
|
static {
|
||||||
|
refresh();
|
||||||
|
logger = InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Re-retrieves all system properties so that any post-launch properties updates are retrieved.
|
||||||
|
*/
|
||||||
|
public static void refresh() {
|
||||||
Properties newProps = null;
|
Properties newProps = null;
|
||||||
try {
|
try {
|
||||||
newProps = System.getProperties();
|
newProps = System.getProperties();
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
logger.warn("Unable to access the system properties; default values will be used.", e);
|
logger.warn("Unable to retrieve the system properties; default values will be used.", e);
|
||||||
newProps = new Properties();
|
newProps = new Properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
props = newProps;
|
synchronized (props) {
|
||||||
|
props.clear();
|
||||||
|
props.putAll(newProps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user