db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1729125 - /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
Date Mon, 08 Feb 2016 10:25:41 GMT
Author: tv
Date: Mon Feb  8 10:25:41 2016
New Revision: 1729125

URL: http://svn.apache.org/viewvc?rev=1729125&view=rev
Log:
Use CopyOnWriteArrayList to avoid synchronization

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java?rev=1729125&r1=1729124&r2=1729125&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
Mon Feb  8 10:25:41 2016
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -511,11 +512,7 @@ public class LargeSelect<T> implements R
 
         List<T> returnResults;
 
-        synchronized (results)
-        {
-            returnResults = new ArrayList<T>(
-                    results.subList(fromIndex, toIndex));
-        }
+        returnResults = new ArrayList<T>(results.subList(fromIndex, toIndex));
 
         position = start + size;
         lastResults = returnResults;
@@ -533,8 +530,7 @@ public class LargeSelect<T> implements R
 
         try
         {
-            // Add 1 to memory limit to check if the query ends on a page break.
-            results = new ArrayList<T>(memoryLimit + 1);
+            results = new CopyOnWriteArrayList<T>();
 
             criteria.setOffset(blockBegin);
             // Add 1 to memory limit to check if the query ends on a
@@ -586,27 +582,25 @@ public class LargeSelect<T> implements R
                     allRecordsRetrieved = true;
                 }
 
+                boolean perhapsLastPage = true;
+                int resultSetSize = tempResults.size();
+
+                // If the extra record was indeed found then we know we are not
+                // on the last page but we must now get rid of it.
+                if (tempResults.size() == memoryLimit + 1)
+                {
+                    results.addAll(tempResults.subList(0, memoryLimit));
+                    resultSetSize--;
+                    perhapsLastPage = false;
+                }
+                else
+                {
+                    results.addAll(tempResults);
+                }
+
                 synchronized (this)
                 {
-                    synchronized (results)
-                    {
-                        results.addAll(tempResults);
-                    }
-
-                    currentlyFilledTo += tempResults.size();
-
-                    boolean perhapsLastPage = true;
-
-                    // If the extra record was indeed found then we know we are not
-                    // on the last page but we must now get rid of it.
-                    if (results.size() == memoryLimit + 1)
-                    {
-                        synchronized (results)
-                        {
-                            results.remove(currentlyFilledTo--);
-                        }
-                        perhapsLastPage = false;
-                    }
+                    currentlyFilledTo += resultSetSize;
 
                     if (results.size() > 0
                         && blockBegin + currentlyFilledTo >= totalRecords)



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message