--- LargeSelect.java    2003-06-17 11:01:19.000000000 +0100
+++ MyLargeSelect.java  2003-06-17 11:12:25.000000000 +0100
@@ -203,6 +203,9 @@
      * longer required.
      */
     private volatile boolean killThread = false;
+    
+    private volatile boolean threadRunning = false;
+
     /**
      * An indication of whether or not the current query has completed
      * processing.
@@ -751,7 +754,7 @@
                 }
                 qds.clearRecords();
             }
-
+           
             log.debug("run(): While loop terminated because either:");
             log.debug("run(): 1. qds.allRecordsRetrieved(): "
                     + qds.allRecordsRetrieved());
@@ -793,6 +796,7 @@
             {
                 log.error(e);
             }
+                       threadRunning = false;
         }
     }
 
@@ -801,13 +805,17 @@
      *
      * @param initialSize the initial size for each block.
      */
-    private void startQuery(int initialSize)
+    private synchronized void startQuery(int initialSize)
     {
-        pageSize = initialSize;
-        currentlyFilledTo = -1;
-        queryCompleted = false;
-        thread = new Thread(this);
-        thread.start();
+        if (!threadRunning)
+        {
+               pageSize = initialSize;
+               currentlyFilledTo = -1;
+               queryCompleted = false;
+               thread = new Thread(this);
+               thread.start();
+               threadRunning = true;
+        }
     }
 
     /**
@@ -816,21 +824,24 @@
      *
      * @throws TorqueException if a sleep is interrupted.
      */
-    private void stopQuery() throws TorqueException
+    private synchronized void stopQuery() throws TorqueException
     {
-        killThread = true;
-        while (thread.isAlive())
+        if (threadRunning)
         {
-            try
-            {
-                Thread.currentThread().sleep(100);
-            }
-            catch (InterruptedException e)
-            {
-                throw new TorqueException("Unexpected interruption",
e);
-            }
-        }
-        killThread = false;
+                       killThread = true;
+               while (thread.isAlive())
+               {
+                   try
+                   {
+                       Thread.currentThread().sleep(100);
+                   }
+                   catch (InterruptedException e)
+                   {
+                       throw new TorqueException("Unexpected
interruption", e);
+                   }
+               }
+               killThread = false;
+            }
     }
 
     /**
@@ -1102,7 +1113,7 @@
      *
      * @throws TorqueException if a sleep is interrupted.
      */
-    public void invalidateResult() throws TorqueException
+    public synchronized void invalidateResult() throws TorqueException
     {
         stopQuery();
         blockBegin = 0;




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to