diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2018-06-21 19:54:37 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-06-21 19:54:37 +0000 |
commit | ec62d8d34ae4724b81d29f6314951c277f423ba4 (patch) | |
tree | c1cb7ca4c4ade0a656bec12c248702b8ce34628c /common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java | |
parent | 88116de291b4200b0d4dfbdfce492d009293dad8 (diff) | |
parent | 902d573db953fd2ac0526717f9d0bc8fbd2ddbed (diff) |
Merge "PropertyUtil: remove sleep when running junit test"
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java')
-rw-r--r-- | common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java index 54e06411..566362c9 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java @@ -36,9 +36,14 @@ import java.util.TimerTask; * notifications of future changes. */ public class PropertyUtil { - - // timer thread used for polling for property file changes - private static Timer timer = null; + + protected static class LazyHolder { + /** + * Timer thread. Will not be allocated by the JVM until it is first referenced. + * This may be overridden by junit tests. + */ + private static Timer timer = new Timer("PropertyUtil-Timer", true); + } // this table maps canonical file into a 'ListenerRegistration' instance private static HashMap<File, ListenerRegistration> registrations = new HashMap<>(); @@ -138,17 +143,6 @@ public class PropertyUtil { // add to static table, so this instance can be shared registrations.put(file, this); - if (timer == null) { - // still need to create a timer thread - synchronized (PropertyUtil.class) { - // an additional check is added inside the 'synchronized' block, - // just in case someone beat us to it - if (timer == null) { - timer = new Timer("PropertyUtil-Timer", true); - } - } - } - // create and schedule the timer task, so this is periodically polled timerTask = new TimerTask() { @Override @@ -160,7 +154,7 @@ public class PropertyUtil { } } }; - timer.schedule(timerTask, 10000L, 10000L); + LazyHolder.timer.schedule(timerTask, 10000L, 10000L); } /** |