JAL-3463 avoid Thread.sleep() as not supported in SwingJS
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 18 May 2020 15:01:54 +0000 (16:01 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 28 May 2020 13:18:07 +0000 (14:18 +0100)
src/jalview/ws/DBRefFetcher.java

index 6b8843d..7daa7b4 100644 (file)
  */
 package jalview.ws;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
 import jalview.analysis.AlignSeq;
 import jalview.api.FeatureSettingsModelI;
 import jalview.bin.Cache;
@@ -36,17 +46,6 @@ import jalview.gui.OOMWarning;
 import jalview.util.DBRefUtils;
 import jalview.util.MessageManager;
 import jalview.ws.seqfetcher.DbSourceProxy;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-import java.util.Vector;
-
 import uk.ac.ebi.picr.model.UPEntry;
 import uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator;
 
@@ -74,8 +73,6 @@ public class DBRefFetcher implements Runnable
 
   CutAndPasteTransfer output = new CutAndPasteTransfer();
 
-  boolean running = false;
-
   /**
    * picr client instance
    */
@@ -225,24 +222,13 @@ public class DBRefFetcher implements Runnable
    */
   public void fetchDBRefs(boolean waitTillFinished)
   {
-    // TODO can we not simply write
-    // if (waitTillFinished) { run(); } else { new Thread(this).start(); }
-
-    Thread thread = new Thread(this);
-    thread.start();
-    running = true;
-
     if (waitTillFinished)
     {
-      while (running)
-      {
-        try
-        {
-          Thread.sleep(500);
-        } catch (Exception ex)
-        {
-        }
-      }
+      run();
+    }
+    else
+    {
+      new Thread(this).start();
     }
   }
 
@@ -295,7 +281,6 @@ public class DBRefFetcher implements Runnable
       throw new Error(MessageManager
               .getString("error.implementation_error_must_init_dbsources"));
     }
-    running = true;
     long startTime = System.currentTimeMillis();
     if (progressWindow != null)
     {
@@ -498,7 +483,6 @@ public class DBRefFetcher implements Runnable
     {
       listener.finished();
     }
-    running = false;
   }
 
   /**