summaryrefslogtreecommitdiffstats
path: root/common-logging/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-06-14 20:09:37 -0400
committerJim Hahn <jrh3@att.com>2018-06-21 15:31:59 -0400
commit902d573db953fd2ac0526717f9d0bc8fbd2ddbed (patch)
tree41aacd45d188dbdeea33fc73b9a1043845aa6f69 /common-logging/src/main
parent5c04cdde760ff9f92235f29f8892977853bce864 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'common-logging/src/main')
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java24
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);
}
/**