From 902d573db953fd2ac0526717f9d0bc8fbd2ddbed Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 14 Jun 2018 20:09:37 -0400 Subject: PropertyUtil: remove sleep when running junit test Update licenses. Remove uneeded dependencies. Make "timer" field private. Make LazyHolder protected. Add comment to TestListener. Combine copyright lines. Change-Id: I77c198c9bc6c224fa93ef74d0c56aa73b187e169 Issue-ID: POLICY-908 Signed-off-by: Jim Hahn --- .../common/logging/flexlogger/PropertyUtil.java | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'common-logging/src/main') 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 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); } /** -- cgit 1.2.3-korg