[prev in list] [next in list] [prev in thread] [next in thread] 

List:       turbine-torque-dev
Subject:    svn commit: r1728482 - /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/
From:       tv () apache ! org
Date:       2016-02-04 13:59:39
Message-ID: 20160204135939.AEE163A0142 () svn01-us-west ! apache ! org
[Download RAW message or body]

Author: tv
Date: Thu Feb  4 13:59:39 2016
New Revision: 1728482

URL: http://svn.apache.org/viewvc?rev=1728482&view=rev
Log:
Replace Thread.sleep with wait/notify and thread.join() respectively.

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=1728482&r1=1728481&r2=1728482&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 \
Thu Feb  4 13:59:39 2016 @@ -211,7 +211,7 @@ public class LargeSelect<T> implements R
     /**
      * The number of milliseconds to sleep before retrying to stop a query.
      */
-    private static final int QUERY_STOP_SLEEP_TIME = 100;
+    private static final int QUERY_STOP_SLEEP_TIME = 1000;
 
     /** A place to store search parameters that relate to this query. */
     private Map<String, String> params = null;
@@ -438,7 +438,7 @@ public class LargeSelect<T> implements R
             {
                 try
                 {
-                    Thread.sleep(QUERY_NOT_COMPLETED_SLEEP_TIME);
+                    wait(QUERY_NOT_COMPLETED_SLEEP_TIME);
                 }
                 catch (InterruptedException e)
                 {
@@ -525,6 +525,7 @@ public class LargeSelect<T> implements R
     /**
      * A background thread that retrieves the rows.
      */
+    @Override
     public void run()
     {
         /* The connection to the database. */
@@ -546,17 +547,14 @@ public class LargeSelect<T> implements R
              * no default peer class inside LargeSelect. This means that all
              * columns not fully qualified will not be modified.
              */
-            String query;
             peer.correctBooleans(
                     criteria);
             peer.setDbName(criteria);
-            query = SqlBuilder.buildQuery(
-                    criteria)
-                .toString();
 
             // Execute the query.
             if (log.isDebugEnabled())
             {
+                String query = SqlBuilder.buildQuery(criteria).toString();
                 log.debug("run(): query = " + query);
                 log.debug("run(): memoryLimit = " + memoryLimit);
                 log.debug("run(): blockBegin = " + blockBegin);
@@ -588,46 +586,51 @@ public class LargeSelect<T> implements R
                     allRecordsRetrieved = true;
                 }
 
-                synchronized (results)
+                synchronized (this)
                 {
-                    results.addAll(tempResults);
-                }
+                    synchronized (results)
+                    {
+                        results.addAll(tempResults);
+                    }
 
-                currentlyFilledTo += tempResults.size();
+                    currentlyFilledTo += tempResults.size();
 
-                boolean perhapsLastPage = true;
+                    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)
+                    // 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)
                     {
-                        results.remove(currentlyFilledTo--);
+                        synchronized (results)
+                        {
+                            results.remove(currentlyFilledTo--);
+                        }
+                        perhapsLastPage = false;
                     }
-                    perhapsLastPage = false;
-                }
 
-                if (results.size() > 0
-                    && blockBegin + currentlyFilledTo >= totalRecords)
-                {
-                    // Add 1 because index starts at 0
-                    totalRecords = blockBegin + currentlyFilledTo + 1;
-                }
+                    if (results.size() > 0
+                        && blockBegin + currentlyFilledTo >= totalRecords)
+                    {
+                        // Add 1 because index starts at 0
+                        totalRecords = blockBegin + currentlyFilledTo + 1;
+                    }
 
-                // if the db has limited the datasets, we must retrieve all
-                // datasets.
-                if (allRecordsRetrieved)
-                {
-                    queryCompleted = true;
-                    // The following ugly condition ensures that the totals are
-                    // not finalized when a user does something like requesting
-                    // a page greater than what exists in the database.
-                    if (perhapsLastPage
-                        && getCurrentPageNumber() <= getTotalPages())
+                    // if the db has limited the datasets, we must retrieve all
+                    // datasets.
+                    if (allRecordsRetrieved)
                     {
-                        totalsFinalized = true;
+                        queryCompleted = true;
+                        // The following ugly condition ensures that the totals are
+                        // not finalized when a user does something like requesting
+                        // a page greater than what exists in the database.
+                        if (perhapsLastPage
+                            && getCurrentPageNumber() <= getTotalPages())
+                        {
+                            totalsFinalized = true;
+                        }
                     }
+
+                    notifyAll();
                 }
             }
 
@@ -712,17 +715,16 @@ public class LargeSelect<T> implements R
         if (threadRunning)
         {
             killThread = true;
-            while (thread.isAlive())
+
+            try
             {
-                try
-                {
-                    Thread.sleep(QUERY_STOP_SLEEP_TIME);
-                }
-                catch (InterruptedException e)
-                {
-                    throw new TorqueException("Unexpected interruption", e);
-                }
+                thread.join(QUERY_STOP_SLEEP_TIME);
             }
+            catch (InterruptedException e)
+            {
+                throw new TorqueException("Unexpected interruption", e);
+            }
+
             killThread = false;
             if (log.isDebugEnabled())
             {



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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic