14.11.5 Using Lambda Syntax

Generally you can perform the following actions in the environment:

  1. Set up the execution environment
  2. Execute task
  3. 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)