Skip to content

Commit

Permalink
Fixing formatting and indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mxro committed Jan 5, 2025
1 parent 3b2290d commit 1940ba2
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/main/java/delight/nashornsandbox/internal/JsEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@

/**
* The JavaScript evaluator. It is designed to run Nashorn engine in separate
* thread (using provided {@link ExecutorService}), to allow limit cpu time
* consumed.
* thread (using provided {@link ExecutorService}), to allow limit cpu time
* consumed.
*
* <p>Created on 2017.11.22</p>
* <p>
* Created on 2017.11.22
* </p>
*
* @author <a href="mailto:[email protected]">Marcin Golebski</a>
* @version $Id$
*/
class JsEvaluator implements Runnable {
private final ThreadMonitor threadMonitor;
private final ScriptEngine scriptEngine;

private Object result = null;
private Exception exception = null;
private final ScriptEngineOperation operation;

JsEvaluator(final ScriptEngine scriptEngine, final long maxCPUTime, final long maxMemory, ScriptEngineOperation operation) {
JsEvaluator(final ScriptEngine scriptEngine, final long maxCPUTime, final long maxMemory,
ScriptEngineOperation operation) {
this.scriptEngine = scriptEngine;
this.threadMonitor = new ThreadMonitor(maxCPUTime, maxMemory);
this.operation = operation;
Expand All @@ -35,37 +38,34 @@ boolean isScriptKilled() {
boolean isCPULimitExceeded() {
return threadMonitor.isCPULimitExceeded();
}

boolean isMemoryLimitExceeded() {
return threadMonitor.isMemoryLimitExceeded();
}

/**
* Enter the monitor method. It should be called from main thread.
* Enter the monitor method. It should be called from main thread.
*/
void runMonitor() {
threadMonitor.run();
}

@Override
public void run() {
try {
boolean registered = threadMonitor.registerThreadToMonitor(Thread.currentThread());
if (registered) {
result = operation.executeScriptEngineOperation(scriptEngine);
}
}
catch (final RuntimeException e) {
} catch (final RuntimeException e) {
// InterruptedException means script was successfully interrupted,
// so no exception should be propagated
if(!(e.getCause() instanceof InterruptedException)) {
if (!(e.getCause() instanceof InterruptedException)) {
exception = e;
}
}
catch (final Exception e) {
} catch (final Exception e) {
exception = e;
}
finally {
} finally {
threadMonitor.scriptFinished();
threadMonitor.stopMonitor();
}
Expand All @@ -74,7 +74,7 @@ public void run() {
Exception getException() {
return exception;
}

Object getResult() {
return result;
}
Expand Down

0 comments on commit 1940ba2

Please sign in to comment.