From 1035922649cc06e41a2aec0069bc2e11011d4121 Mon Sep 17 00:00:00 2001 From: serso Date: Fri, 28 Oct 2011 00:29:46 +0400 Subject: [PATCH] interrupt work thread --- .../solovyev/android/calculator/model/CalculatorEngine.java | 6 +++++- .../android/calculator/model/CalculatorEngineTest.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java index 7affa24f..040ba0f9 100644 --- a/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java +++ b/src/main/java/org/solovyev/android/calculator/model/CalculatorEngine.java @@ -8,6 +8,7 @@ package org.solovyev.android.calculator.model; import android.content.Context; import android.content.SharedPreferences; import jscl.math.Expression; +import jscl.text.ParseInterruptedException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.solovyev.android.calculator.R; @@ -177,6 +178,9 @@ public enum CalculatorEngine { calculationResult.setObject(finalOperation.evaluate(Expression.valueOf(jsclExpression))); } catch (jscl.text.ParseException e) { exception.setObject(new ParseException(e)); + } catch (ParseInterruptedException e) { + System.out.print("Interrupted!"); + // do nothing - we ourselves interrupt the calculations } finally { //Log.d(CalculatorEngine.class.getName(), "Calculation thread ended work: " + thread.getName()); calculationThread.setObject(null); @@ -187,7 +191,7 @@ public enum CalculatorEngine { try { //Log.d(CalculatorEngine.class.getName(), "Main thread is waiting: " + Thread.currentThread().getName()); - latch.await(3000, TimeUnit.SECONDS); + latch.await(2, TimeUnit.SECONDS); //Log.d(CalculatorEngine.class.getName(), "Main thread got up: " + Thread.currentThread().getName()); final ParseException evalErrorLocal = exception.getObject(); diff --git a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java index a177d9e4..c4af15c4 100644 --- a/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java +++ b/src/test/java/org/solovyev/android/calculator/model/CalculatorEngineTest.java @@ -18,6 +18,7 @@ import java.util.Locale; * Date: 9/17/11 * Time: 9:47 PM */ + public class CalculatorEngineTest { @BeforeClass @@ -35,7 +36,7 @@ public class CalculatorEngineTest { cm.evaluate(JsclOperation.numeric, "3^10^10^10"); Assert.fail(); } catch (ParseException e) { - if (e.getCause().getMessage().startsWith("Too big")) { + if (e.getMessage().startsWith("Too long calculation")) { } else { System.out.print(e.getCause().getMessage());