From: Jim Procter Date: Fri, 18 Dec 2020 11:37:02 +0000 (+0000) Subject: JAL-3690 recoded AWSThread to use javax.swing.Timer (see https://github.com/BobHanson... X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=ab7d77e52196fa14fbfe35c6373c069e4b0ba6f0 JAL-3690 recoded AWSThread to use javax.swing.Timer (see https://github.com/BobHanson/java2script/issues/195#issuecomment-747695834 )- web service submission works, but doesn’t seem to be happening as a background task. --- diff --git a/src/jalview/ws/AWSThread.java b/src/jalview/ws/AWSThread.java index 096f4ee..5748414a 100644 --- a/src/jalview/ws/AWSThread.java +++ b/src/jalview/ws/AWSThread.java @@ -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(); } /**