geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject [41/51] [abbrv] geronimo-yoko git commit: Use initialization holder class idiom
Date Sun, 19 Feb 2017 01:49:58 GMT
Use initialization holder class idiom


Project: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/repo
Commit: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/commit/e5a052ea
Tree: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/tree/e5a052ea
Diff: http://git-wip-us.apache.org/repos/asf/geronimo-yoko/diff/e5a052ea

Branch: refs/heads/master
Commit: e5a052ea0e5d6b7e64522835e0d57a273f65ee06
Parents: bc1c6a4
Author: Neil GM Richards <neil_richards@uk.ibm.com>
Authored: Tue Jun 21 09:28:17 2016 +0100
Committer: Neil GM Richards <neil_richards@uk.ibm.com>
Committed: Tue Jun 21 09:28:17 2016 +0100

----------------------------------------------------------------------
 .../apache/yoko/rmi/impl/TypeRepository.java    | 22 +++++--------------
 .../apache/yoko/rmi/impl/ValueHandlerImpl.java  | 23 +++++---------------
 2 files changed, 12 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/e5a052ea/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
index 31c2d4f..e7fc362 100755
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/TypeRepository.java
@@ -34,7 +34,6 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -257,22 +256,13 @@ public class TypeRepository {
         }
     }
 
-    private static final AtomicReference<WeakReference<TypeRepository>> singletonWeakRef
= new AtomicReference<>();
+    private static enum RepoHolder {
+        ;
+        static final TypeRepository value = new TypeRepository();
+    }
+
     public static TypeRepository get() {
-        TypeRepository repo = null;
-        WeakReference<TypeRepository> weakRef = singletonWeakRef.get();
-        if (null != weakRef) {
-            repo = weakRef.get();
-            if (null != repo) return repo;
-        }
-        final TypeRepository newRepo = new TypeRepository();
-        final WeakReference<TypeRepository> newRef = new WeakReference<>(newRepo);
-        while(!!!singletonWeakRef.compareAndSet(weakRef, newRef)) {
-            weakRef = singletonWeakRef.get();
-            repo = weakRef.get();
-            if (null != repo) return repo;
-        }
-        return newRepo;
+        return RepoHolder.value;
     }
 
     public String getRepositoryID(Class<?> type) {

http://git-wip-us.apache.org/repos/asf/geronimo-yoko/blob/e5a052ea/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueHandlerImpl.java
----------------------------------------------------------------------
diff --git a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueHandlerImpl.java b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueHandlerImpl.java
index 0ed86c0..8a8bd23 100755
--- a/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueHandlerImpl.java
+++ b/yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/ValueHandlerImpl.java
@@ -18,8 +18,6 @@
 
 package org.apache.yoko.rmi.impl;
 
-import java.lang.ref.WeakReference;
-import java.util.concurrent.atomic.AtomicReference;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -43,22 +41,13 @@ public class ValueHandlerImpl implements ValueHandler {
         this.repo = TypeRepository.get();
     }
 
-    private static final AtomicReference<WeakReference<ValueHandlerImpl>> singletonWeakRef
= new AtomicReference<>();
+    private static enum HandlerHolder {
+        ;
+        static final ValueHandlerImpl value = new ValueHandlerImpl();
+    }
+
     public static ValueHandlerImpl get() {
-        ValueHandlerImpl vh = null;
-        WeakReference<ValueHandlerImpl> weakRef = singletonWeakRef.get();
-        if (null != weakRef) {
-            vh = weakRef.get();
-            if (null != vh) return vh;
-        }
-        final ValueHandlerImpl newVh = new ValueHandlerImpl();
-        final WeakReference<ValueHandlerImpl> newRef = new WeakReference<>(newVh);
-        while(!!!singletonWeakRef.compareAndSet(weakRef, newRef)) {
-            weakRef = singletonWeakRef.get();
-            vh = weakRef.get();
-            if (null != vh) return vh;
-        }
-        return newVh;
+        return HandlerHolder.value;
     }
 
     private ValueDescriptor desc(Class clz) {


Mime
View raw message