From b4ae8d066222da1235d4bc27581a810b1569d914 Mon Sep 17 00:00:00 2001 From: Alexander Dorokhine Date: Fri, 10 Mar 2017 16:22:23 -0800 Subject: Use double-checked locking instead of 'synchronized' in EventCache. (#52) * Use double-checked locking instead of 'synchronized' in EventCache. --- .../java/com/google/android/mobly/snippet/event/EventCache.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'third_party') diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java index 3d8775f..d150987 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/event/EventCache.java @@ -42,9 +42,13 @@ public class EventCache { private EventCache() {} - public static synchronized EventCache getInstance() { + public static EventCache getInstance() { if (mEventCache == null) { - mEventCache = new EventCache(); + synchronized (EventCache.class) { + if (mEventCache == null) { + mEventCache = new EventCache(); + } + } } return mEventCache; } -- cgit v1.2.3