[jboss-cvs] JBossAS SVN: r88904 - projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu May 14 16:42:20 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-05-14 16:42:20 -0400 (Thu, 14 May 2009)
New Revision: 88904

Modified:
   projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/AtomicArray.java
Log:
Remove dep on JDK1.6 method

Modified: projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/AtomicArray.java
===================================================================
--- projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/AtomicArray.java	2009-05-14 20:34:56 UTC (rev 88903)
+++ projects/jboss-threads/trunk/main/src/main/java/org/jboss/threads/AtomicArray.java	2009-05-14 20:42:20 UTC (rev 88904)
@@ -27,6 +27,8 @@
 import java.util.Comparator;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 
+import java.util.logging.Handler;
+
 /**
  * Utility for snapshot/copy-on-write arrays.  To use these methods, two things are required: an immutable array
  * stored on a volatile field, and an instance of
@@ -98,6 +100,13 @@
         return updater.getAndSet(instance, value);
     }
 
+    @SuppressWarnings({ "unchecked" })
+    private static <V> V[] copyOf(final Class<V> componentType, V[] old, int newLen) {
+        final V[] target = newInstance(componentType, newLen);
+        System.arraycopy(old, 0, target, 0, Math.min(old.length, newLen));
+        return target;
+    }
+
     /**
      * Atomically replace the array with a new array which is one element longer, and which includes the given value.
      *
@@ -109,7 +118,7 @@
         for (;;) {
             final V[] oldVal = updater.get(instance);
             final int oldLen = oldVal.length;
-            final V[] newVal = Arrays.copyOf(oldVal, oldLen + 1);
+            final V[] newVal = copyOf(componentType, oldVal, oldLen + 1);
             newVal[oldLen] = value;
             if (updater.compareAndSet(instance, oldVal, newVal)) {
                 return;
@@ -144,7 +153,7 @@
                     }
                 }
             }
-            final V[] newVal = Arrays.copyOf(oldVal, oldLen + 1);
+            final V[] newVal = copyOf(componentType, oldVal, oldLen + 1);
             newVal[oldLen] = value;
             if (updater.compareAndSet(instance, oldVal, newVal)) {
                 return true;
@@ -360,6 +369,10 @@
 
     @SuppressWarnings({ "unchecked" })
     private static <V> V[] newInstance(Class<V> componentType, int length) {
-        return (V[]) Array.newInstance(componentType, length);
+        if (componentType == Handler.class) {
+            return (V[]) new Handler[length];
+        } else {
+            return (V[]) Array.newInstance(componentType, length);
+        }
     }
 }




More information about the jboss-cvs-commits mailing list