Class SandboxExecutor
SandboxLimits.
IScriptEvaluator se = ...;
se.setSandboxPolicy(policy);
se.cook(script);
SandboxExecutor executor = new SandboxExecutor(limits);
Object result = executor.call(() -> se.evaluate(arguments));
Each call(Callable) executes the task on a new thread. Code that JANINO compiled with a SandboxPolicy checks the limits regularly (see Guard) and stops when one is exceeded. Code from other
compilers is only subject to the timeout, and cannot be stopped: when it does not terminate after the timeout,
its thread is abandoned (see SandboxLimitExceededException.isThreadTerminated()).
The limits apply only to code that runs inside call(Callable); e.g. the instantiation of a generated
class (which runs its static initializer and its constructor), and the methods of an object that the sandboxed
code returns, and which the host invokes later, must also be executed through a SandboxExecutor. SandboxPolicy.Builder.requireExecutor() makes sure that this is not forgotten.
-
Constructor Summary
ConstructorsConstructorDescriptionSandboxExecutor(SandboxLimits limits) Uses daemon threads.SandboxExecutor(SandboxLimits limits, ThreadFactory threadFactory) -
Method Summary
Modifier and TypeMethodDescription<T> TExecutes the task on a new thread and waits until it completes or the timeout expires.
-
Constructor Details
-
SandboxExecutor
Uses daemon threads. -
SandboxExecutor
- Parameters:
threadFactory- Creates the threads that execute the tasks;nullmeans to create daemon threads
-
-
Method Details
-
getLimits
-
call
Executes the task on a new thread and waits until it completes or the timeout expires.- Returns:
- The result of the task
- Throws:
SandboxLimitExceededException- The task exceeded a limit (even if it caught theSandboxLimitExceededError); its result is discardedInterruptedException- The current thread was interrupted while waiting; the task is cancelledException- The task threw it
-