interrupt work thread
This commit is contained in:
parent
952f5b54ad
commit
9720109905
@ -8,6 +8,7 @@ package org.solovyev.android.calculator.model;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import jscl.math.Expression;
|
import jscl.math.Expression;
|
||||||
|
import jscl.text.ParseInterruptedException;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
@ -177,6 +178,9 @@ public enum CalculatorEngine {
|
|||||||
calculationResult.setObject(finalOperation.evaluate(Expression.valueOf(jsclExpression)));
|
calculationResult.setObject(finalOperation.evaluate(Expression.valueOf(jsclExpression)));
|
||||||
} catch (jscl.text.ParseException e) {
|
} catch (jscl.text.ParseException e) {
|
||||||
exception.setObject(new ParseException(e));
|
exception.setObject(new ParseException(e));
|
||||||
|
} catch (ParseInterruptedException e) {
|
||||||
|
System.out.print("Interrupted!");
|
||||||
|
// do nothing - we ourselves interrupt the calculations
|
||||||
} finally {
|
} finally {
|
||||||
//Log.d(CalculatorEngine.class.getName(), "Calculation thread ended work: " + thread.getName());
|
//Log.d(CalculatorEngine.class.getName(), "Calculation thread ended work: " + thread.getName());
|
||||||
calculationThread.setObject(null);
|
calculationThread.setObject(null);
|
||||||
@ -187,7 +191,7 @@ public enum CalculatorEngine {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
//Log.d(CalculatorEngine.class.getName(), "Main thread is waiting: " + Thread.currentThread().getName());
|
//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());
|
//Log.d(CalculatorEngine.class.getName(), "Main thread got up: " + Thread.currentThread().getName());
|
||||||
|
|
||||||
final ParseException evalErrorLocal = exception.getObject();
|
final ParseException evalErrorLocal = exception.getObject();
|
||||||
|
@ -18,6 +18,7 @@ import java.util.Locale;
|
|||||||
* Date: 9/17/11
|
* Date: 9/17/11
|
||||||
* Time: 9:47 PM
|
* Time: 9:47 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CalculatorEngineTest {
|
public class CalculatorEngineTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@ -35,7 +36,7 @@ public class CalculatorEngineTest {
|
|||||||
cm.evaluate(JsclOperation.numeric, "3^10^10^10");
|
cm.evaluate(JsclOperation.numeric, "3^10^10^10");
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
if (e.getCause().getMessage().startsWith("Too big")) {
|
if (e.getMessage().startsWith("Too long calculation")) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.print(e.getCause().getMessage());
|
System.out.print(e.getCause().getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user