interrupt work thread

This commit is contained in:
serso 2011-10-28 00:29:46 +04:00
parent 952f5b54ad
commit 9720109905
2 changed files with 7 additions and 2 deletions

View File

@ -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();

View File

@ -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());