|Modifier and Type||Method and Description|
Builds the limit configuration object.
Notified when a resource limit is reached.
Specifies the maximum number of statements a context may execute until the onLimit event is notified and the context will be
public ResourceLimits.Builder statementLimit(long limit, Predicate<Source> sourceFilter)
closed. After the statement limit was triggered for a context, it is no longer usable and every use of the context will throw a
PolyglotException.isCancelled(). The statement limit is independent of the number of threads executing and is applied per context. Invoking this method multiple times overwrites previous statement limit configurations. If the statement limit is exceeded then the
onLimitlistener is notified.
By default there is no statement limit applied. The limit may be set to 0 to disable it.
In addition to the limit a source filter may be set to indicate for which sources the
limit should be applied. If the source filter is
null then it will be
applied to all
internal and public sources. The provided
limit must not be negative otherwise an
IllegalArgumentException is thrown. If a
shared engine is used then the same source filter
instance must be used for all contexts of an engine. Otherwise an
IllegalArgumentException is thrown when the context is
built. The limit itself may vary between contexts.
The statement limit is applied to the context and all inner contexts it spawns. Therefore, new inner contexts cannot be used to exceed the statement limit.
Note that attaching a statement limit to a context reduces the throughput of all guest applications with the same engine. The statement counter needs to be updated with every statement that is executed. It is recommended to benchmark the use of the statement limit before it is used in production.
Note that the complexity of a single statement may not be constant time depending on the
Array.sort, may account for a single statement, but its execution time is
dependent on the size of the array. The statement count limit is therefore not suitable
to perform time boxing and must be combined with other more reliable measures.
public ResourceLimits.Builder onLimit(Consumer<ResourceLimitEvent> onLimit)
null. May be set to
nullto disable events.