JAL-3690 recoded AWSThread to use javax.swing.Timer (see https://github.com/BobHanson... merge/Jalview-JS/develop_feature/JAL-3690_callback-based-web-services
authorJim Procter <jprocter@issues.jalview.org>
Fri, 18 Dec 2020 11:37:02 +0000 (11:37 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Fri, 18 Dec 2020 11:37:58 +0000 (11:37 +0000)
src/jalview/ws/AWSThread.java

index 096f4ee..5748414 100644 (file)
@@ -33,15 +33,17 @@ import jalview.viewmodel.seqfeatures.FeatureRendererSettings;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
 
 import static java.lang.String.format;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import javax.swing.Timer;
+
 public abstract class AWSThread
 {
   
-  private final Timer timer = new Timer();
+  private javax.swing.Timer timer;
 
   /**
    * view that this job was associated with
@@ -116,9 +118,11 @@ public abstract class AWSThread
       wsInfo.setFinishedNoResults();
       return;
     }
-    TimerTask task = new TimerTask() {
+    timer = new Timer(5000, new ActionListener()
+    {
+      
       @Override
-      public void run() 
+      public void actionPerformed(ActionEvent e)
       {
         JobStateSummary jstate = new JobStateSummary();
         for (final AWsJob job : jobs)
@@ -181,13 +185,15 @@ public abstract class AWSThread
         updateGlobalStatus(jstate);
         if (jobComplete)
         {
+          timer.stop();
           // jobs should never be null at this point
           parseResult(); // tidy up and make results available to user
-          timer.cancel();
+          
         }
       }
-    };
-    timer.schedule(task, 0, 5000);
+    });
+    timer.setInitialDelay(0);
+    timer.start();
   }
 
   protected void updateGlobalStatus(JobStateSummary jstate)
@@ -220,7 +226,7 @@ public abstract class AWSThread
   
   public void interrupt()
   {
-    timer.cancel();
+    timer.stop();
   }
 
   /**