From 40bdbd1948237a62b5c2841d8a0efe686ade3335 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 7 Aug 2017 08:58:47 -0700 Subject: [PATCH] Add a timer to the computation thread to stop it from running. --- .../java/org/nwapw/abacus/fx/AbacusController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 06b10ac..96d5ad3 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -124,6 +124,17 @@ public class AbacusController implements PluginListener { * The alert shown when a press to "apply" is needed. */ private Alert reloadAlert; + /** + * The runnable that takes care of killing computations that take too long. + */ + private final Runnable TIMER_RUNNABLE = () -> { + try { + Thread.sleep(30 * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + performStop(); + }; /** * The runnable used to perform the calculation. */ @@ -239,6 +250,7 @@ public class AbacusController implements PluginListener { stopButton.setDisable(false); calculationThread = new Thread(CALCULATION_RUNNABLE); calculationThread.start(); + new Thread(TIMER_RUNNABLE).start(); } @FXML