public final class ResourceLimits extends Object
builder
and activated by
enabling
them for a context
. All configured limits are applied per context instance. Resource limits may be
reset
. If a resource limit is triggered the context that triggered
the limit will automatically be closed
and can no longer be used
to evaluate code.
The following resource limits are supported:
Statement count
limit per context. Allows to
limit the amount of statements executed per context.
ResourceLimits limits = ResourceLimits.newBuilder()
.statementLimit(500, null)
.build();
try (Context context = Context.newBuilder("js")
.resourceLimits(limits)
.build();) {
try {
context.eval("js", "while(true);");
assert false;
} catch (PolyglotException e) {
// triggered after 500 iterations of while(true);
// context is closed and can no longer be used
assert e.isCancelled();
}
}
ResourceLimits.newBuilder()
Modifier and Type | Class and Description |
---|---|
class |
ResourceLimits.Builder
A builder used to construct resource limits.
|
Modifier and Type | Method and Description |
---|---|
static ResourceLimits.Builder |
newBuilder()
Creates a new builder to construct
ResourceLimits instances. |
public static ResourceLimits.Builder newBuilder()
ResourceLimits
instances.