aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-12-20 11:20:39 +0100
committerJiri Vanek <[email protected]>2013-12-20 11:20:39 +0100
commit99428f6f586269f4b5856f93adb71385f6c64c97 (patch)
treef13560c1d4d7200583dc858b1ad8c387023f5013 /netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
parentc3b3c491051c08e035593a25850e537168bb1db9 (diff)
singletons logic, logs and test cleanup/fixes
Diffstat (limited to 'netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java')
-rw-r--r--netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java44
1 files changed, 28 insertions, 16 deletions
diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
index 3ec3f91..ac510ba 100644
--- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
+++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
@@ -90,8 +90,6 @@ public class JNLPRuntime {
/** the localized resource strings */
private static ResourceBundle resources;
- private static DeploymentConfiguration config;
-
/** the security manager */
private static JNLPSecurityManager security;
@@ -351,25 +349,39 @@ public class JNLPRuntime {
/**
- * Gets the Configuration associated with this runtime
- * @return a {@link DeploymentConfiguration} object that can be queried to
- * find relevant configuration settings
+ * see https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
+ * for cases how not to do lazy initialization
+ * and https://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom
+ * for ITW approach
*/
- public synchronized static DeploymentConfiguration getConfiguration() {
- if (config == null){
- config = new DeploymentConfiguration();
- try{
+ private static class DeploymentConfigurationHolder {
+
+ private static final DeploymentConfiguration INSTANCE = initConfiguration();
+
+ private static DeploymentConfiguration initConfiguration() {
+ DeploymentConfiguration config = new DeploymentConfiguration();
+ try {
config.load();
config.copyTo(System.getProperties());
- }catch(ConfigurationException ex){
- OutputController.getLogger().log(ex);
- //mark first occurence of exception so we can react later
- if (config.getLoadingException() == null){
- config.setLoadingException(ex);
- }
+ } catch (ConfigurationException ex) {
+ OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, getMessage("RConfigurationError"));
+ //mark this exceptionas we can die on it later
+ config.setLoadingException(ex);
+ } finally {
+ OutputController.getLogger().startConsumer();
}
+ return config;
}
- return config;
+ }
+
+ /**
+ * Gets the Configuration associated with this runtime
+ *
+ * @return a {@link DeploymentConfiguration} object that can be queried to
+ * find relevant configuration settings
+ */
+ public static DeploymentConfiguration getConfiguration() {
+ return DeploymentConfigurationHolder.INSTANCE;
}
/**