From ab7d77e52196fa14fbfe35c6373c069e4b0ba6f0 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 18 Dec 2020 11:37:02 +0000 Subject: [PATCH] =?utf8?q?JAL-3690=20recoded=20AWSThread=20to=20use=20javax.?= =?utf8?q?swing.Timer=20(see=20https://github.com/BobHanson/java2script/issu?= =?utf8?q?es/195#issuecomment-747695834=20)-=20web=20service=20submission=20?= =?utf8?q?works,=20but=20doesn=E2=80=99t=20seem=20to=20be=20happening=20as=20?= =?utf8?q?a=20background=20task.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/jalview/ws/AWSThread.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) 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(); } /** -- 1.7.10.2