interrupt work thread
This commit is contained in:
parent
9720109905
commit
478b1af548
@ -78,6 +78,9 @@ public enum CalculatorEngine {
|
||||
@NotNull
|
||||
private ThreadKiller threadKiller = new AndroidThreadKiller();
|
||||
|
||||
// calculation thread timeout in milliseconds, after timeout thread would be interrupted
|
||||
private int timeout = 2000;
|
||||
|
||||
@NotNull
|
||||
public String format(@NotNull Double value) {
|
||||
return format(value, true);
|
||||
@ -191,7 +194,7 @@ public enum CalculatorEngine {
|
||||
|
||||
try {
|
||||
//Log.d(CalculatorEngine.class.getName(), "Main thread is waiting: " + Thread.currentThread().getName());
|
||||
latch.await(2, TimeUnit.SECONDS);
|
||||
latch.await(timeout, TimeUnit.MILLISECONDS);
|
||||
//Log.d(CalculatorEngine.class.getName(), "Main thread got up: " + Thread.currentThread().getName());
|
||||
|
||||
final ParseException evalErrorLocal = exception.getObject();
|
||||
@ -281,6 +284,11 @@ public enum CalculatorEngine {
|
||||
return varsRegister;
|
||||
}
|
||||
|
||||
// for tests
|
||||
void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/* private String commands(String str) {
|
||||
return commands(str, false);
|
||||
}
|
||||
|
@ -117,6 +117,14 @@ public class CalculatorEngineTest {
|
||||
junit.framework.Assert.fail();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
cm.setTimeout(5000);
|
||||
Assert.assertEquals("2", cm.evaluate(JsclOperation.numeric, "2!").getResult());
|
||||
} finally {
|
||||
cm.setTimeout(2000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user