Add SystemPropertyUtil.refresh()
This commit is contained in:
parent
5a9d6e59c1
commit
21c9c26ff8
@ -25,25 +25,34 @@ import java.util.Properties;
|
||||
*/
|
||||
public final class SystemPropertyUtil {
|
||||
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(SystemPropertyUtil.class);
|
||||
|
||||
private static final Properties props;
|
||||
private static final Properties props = new Properties();
|
||||
private static final InternalLogger logger;
|
||||
|
||||
// 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 on every system property access or introducing more complexity
|
||||
// just because of less verbose logging.
|
||||
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;
|
||||
try {
|
||||
newProps = System.getProperties();
|
||||
} 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();
|
||||
}
|
||||
|
||||
props = newProps;
|
||||
synchronized (props) {
|
||||
props.clear();
|
||||
props.putAll(newProps);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user