Class SandboxLimits
java.lang.Object
org.codehaus.commons.compiler.sandbox.SandboxLimits
The resource limits for one execution of sandboxed code by a
SandboxExecutor. Whereas a SandboxPolicy determines what code may do, the limits determine how much of it.
A SandboxLimits object is immutable; use a SandboxLimits.Builder to create one:
SandboxLimits limits = SandboxLimits.builder()
.timeout(2, TimeUnit.SECONDS)
.maxTicks(10_000_000)
.maxAllocatedBytes(64L << 20)
.build();
All limits are optional; a limit that is not set is not enforced.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classCreatesSandboxLimits.static enumThe kinds of resource limits. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe value of a limit that is not set. -
Method Summary
Modifier and TypeMethodDescriptionstatic SandboxLimits.Builderbuilder()longlonglongstatic booleantoString()
-
Field Details
-
UNLIMITED
public static final long UNLIMITEDThe value of a limit that is not set.- See Also:
-
-
Method Details
-
isMemoryLimitSupported
public static boolean isMemoryLimitSupported()- Returns:
- Whether this JVM can measure the memory that a thread allocates; if not, then
SandboxLimits.Builder.maxAllocatedBytes(long)is not enforced
-
builder
- Returns:
- A new builder for limits that initially limit nothing
-
getTimeoutNanos
public long getTimeoutNanos()- Returns:
- The timeout in nanoseconds, or
UNLIMITED
-
getMaxTicks
public long getMaxTicks()- Returns:
- The maximum number of ticks, or
UNLIMITED - See Also:
-
getMaxAllocatedBytes
public long getMaxAllocatedBytes()- Returns:
- The maximum number of bytes that the executing thread may allocate, or
UNLIMITED
-
toString
-