ref #7699: wait for the thread to stop
authorKatja Luther <k.luther@bgbm.org>
Thu, 14 Jan 2021 10:43:33 +0000 (11:43 +0100)
committerKatja Luther <k.luther@bgbm.org>
Thu, 14 Jan 2021 10:43:33 +0000 (11:43 +0100)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/input/AbstractBulkEditorInput.java

index 105a612763bce68c5f2fdddcc41feba52afbdd90..747dc3df644b3d366599870eb49a169cda42dc6f 100644 (file)
@@ -227,19 +227,28 @@ public abstract class AbstractBulkEditorInput<T extends CdmBase>
        public void performSearch(final BulkEditorQuery bulkEditorQuery, IStructuredSelection selection) {
            //cancel previous search job
            if(searchJob!=null && searchJob.getState()!=Job.NONE){
-               searchJob.cancel();
+               boolean isCanceled = searchJob.cancel();
+               if (!isCanceled){
+                   while (!isCanceled){
+                   try {
+                       Thread.sleep(200);
+                   } catch (InterruptedException e) {
+                   }
+                   isCanceled = searchJob.cancel();
+                   }
+               }
                searchJob = null;
-               /*
-                * wait for a little while for the job to finish
-                * to avoid asynchronously loaded results of the
-                * previous search being shown in the next search
-                * (not critical but explicitly waiting for the job to finish
-                * could run into an endless loop by mistake)
-                */
-               try {
-                Thread.sleep(500);
-            } catch (InterruptedException e) {
-            }
+//             /*
+//              * wait for a little while for the job to finish
+//              * to avoid asynchronously loaded results of the
+//              * previous search being shown in the next search
+//              * (not critical but explicitly waiting for the job to finish
+//              * could run into an endless loop by mistake)
+//              */
+//             try {
+//                Thread.sleep(500);
+//            } catch (InterruptedException e) {
+//            }
            }
         model.clear();
         markedMergeCandidates.clear();