14.11.5 Using Lambda Syntax
Generally you can perform the following actions in the environment:
- Set up the execution environment
- Execute task
- Reset execution environment
All these actions can be combined and performed in a single step using the set
method. For each set
method there is a method using the with
prefix which takes the updated value and a lambda which should be executed using the updated value.
For example, use withNumThreadsPerTask()
instead of setNumThreadsPerTask()
as shown:
opg4j> var g = ioEnv.withNumThreadsPerTask(8, () -> session.readGraphWithProperties(...))
==> PgxGraph[name=graph,N=3,E=6,created=0]
import oracle.pgx.api.*;
import oracle.pgx.api.executionenvironment.*;
PgxGraph g = ioEnv.withNumThreadsPerTask(8, () -> session.readGraphWithProperties(...));
The preceding code execution is equivalent to the following sequence of actions:
var oldValue = ioEnv.getNumThreadsPerTask()
ioEnv.setNumThreadsPerTask(currentValue)
var g = session.readGraphWithProperties(...)
ioEnv.setNumThreadsPerTask(oldValue)
Parent topic: Advanced Task Scheduling Using Execution Environments