geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1386839 - /geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
Date Mon, 17 Sep 2012 21:09:17 GMT
Author: gawor
Date: Mon Sep 17 21:09:16 2012
New Revision: 1386839

URL: http://svn.apache.org/viewvc?rev=1386839&view=rev
Log:
Avoid synchronization by using AtomicReference

Modified:
    geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java

Modified: geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java?rev=1386839&r1=1386838&r2=1386839&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
(original)
+++ geronimo/specs/trunk/geronimo-el_2.2_spec/src/main/java/javax/el/CompositeELResolver.java
Mon Sep 17 21:09:16 2012
@@ -19,16 +19,14 @@ package javax.el;
 
 import java.beans.FeatureDescriptor;
 import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicReference;
 
 public class CompositeELResolver extends ELResolver {
 
-    private int size;
-
-    private ELResolver[] resolvers;
+    private AtomicReference<ELResolver[]> resolvers;
 
     public CompositeELResolver() {
-        this.size = 0;
-        this.resolvers = new ELResolver[2];
+        this.resolvers = new AtomicReference<ELResolver[]>(new ELResolver[0]);
     }
 
     synchronized public void add(ELResolver elResolver) {
@@ -36,23 +34,23 @@ public class CompositeELResolver extends
             throw new NullPointerException();
         }
 
-        if (this.size >= this.resolvers.length) {
-            ELResolver[] nr = new ELResolver[this.size * 2];
-            System.arraycopy(this.resolvers, 0, nr, 0, this.size);
-            this.resolvers = nr;
-        }
-        this.resolvers[this.size++] = elResolver;
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+        
+        ELResolver[] nr = new ELResolver[sz + 1];
+        System.arraycopy(rslvrs, 0, nr, 0, sz);
+        nr[sz] = elResolver;
+        
+        resolvers.set(nr);
     }
 
     public Object getValue(ELContext context, Object base, Object property)
             throws NullPointerException, PropertyNotFoundException, ELException {
         context.setPropertyResolved(false);
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         Object result = null;
         for (int i = 0; i < sz; i++) {
             result = rslvrs[i].getValue(context, base, property);
@@ -68,12 +66,10 @@ public class CompositeELResolver extends
             PropertyNotFoundException, PropertyNotWritableException,
             ELException {
         context.setPropertyResolved(false);
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         for (int i = 0; i < sz; i++) {
             rslvrs[i].setValue(context, base, property, value);
             if (context.isPropertyResolved()) {
@@ -85,12 +81,10 @@ public class CompositeELResolver extends
     public boolean isReadOnly(ELContext context, Object base, Object property)
             throws NullPointerException, PropertyNotFoundException, ELException {
         context.setPropertyResolved(false);
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         boolean readOnly = false;
         for (int i = 0; i < sz; i++) {
             readOnly = rslvrs[i].isReadOnly(context, base, property);
@@ -101,17 +95,16 @@ public class CompositeELResolver extends
         return false;
     }
 
-    synchronized public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext
context, Object base) {
-        return new FeatureIterator(context, base, this.resolvers, this.size);
+    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object
base) {        
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+        return new FeatureIterator(context, base, rslvrs, sz);
     }
 
     public Class<?> getCommonPropertyType(ELContext context, Object base) {
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         Class<?> commonType = null, type = null;
         for (int i = 0; i < sz; i++) {
             type = rslvrs[i].getCommonPropertyType(context, base);
@@ -126,12 +119,10 @@ public class CompositeELResolver extends
     public Class<?> getType(ELContext context, Object base, Object property)
             throws NullPointerException, PropertyNotFoundException, ELException {
         context.setPropertyResolved(false);
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         Class<?> type;
         for (int i = 0; i < sz; i++) {
             type = rslvrs[i].getType(context, base, property);
@@ -220,12 +211,10 @@ public class CompositeELResolver extends
         if (context.getContext(ExpressionFactory.class) == null) {
             context.putContext(ExpressionFactory.class, expressionFactory);
         }
-        int sz;
-        ELResolver[] rslvrs;
-        synchronized (this) {
-            sz = this.size;
-            rslvrs = this.resolvers;
-        }
+
+        ELResolver[] rslvrs = resolvers.get();
+        int sz = rslvrs.length;
+
         Object retValue = null;
         for (int i = 0; i < sz; i++) {
             retValue = rslvrs[i].invoke(context, base, targetMethod, paramTypes, params);



Mime
View raw message