WorkerExecutor

API Documentation:WorkerExecutor

Note: This class is incubating and may change in a future version of Gradle.

Allows work to be submitted for asynchronous execution. This api allows for safe, concurrent execution of work items and enables:

  • Parallel execution of work items within a single task
  • Execution in isolated contexts such as an isolated classloader or even a separate process
  • Safe execution of multiple tasks in parallel

Work should be submitted with a Runnable class representing the implementation of the unit of work and an action to configure the unit of work (via WorkerConfiguration).

workerExecutor.submit(RunnableWorkImpl.class) { WorkerConfiguration conf ->
    // Set the isolation mode for the worker
    conf.isolationMode = IsolationMode.NONE

    // Set up the constructor parameters for the unit of work
    conf.params = [ "foo", file('bar') ]
}

Properties

No properties

Methods

MethodDescription
await()
Incubating

Blocks until all work associated with the current build operation is complete. Note that when using this method inside a task action, it will block completion of the task action until all submitted work is complete. This means that other tasks from the same project cannot be run in parallel while the task action is still executing.

submit(actionClass, configAction)
Incubating

Submits a piece of work to be executed asynchronously. Execution of the work may begin immediately. Work configured with IsolationMode.PROCESS will execute in an idle daemon that meets the requirements set in the WorkerConfiguration. If no idle daemons are available, a new daemon will be started. Any errors will be thrown from WorkerExecutor.await() or from the surrounding task action if WorkerExecutor.await() is not used.

Script blocks

No script blocks

Method details

void await()

Note: This method is incubating and may change in a future version of Gradle.

Blocks until all work associated with the current build operation is complete. Note that when using this method inside a task action, it will block completion of the task action until all submitted work is complete. This means that other tasks from the same project cannot be run in parallel while the task action is still executing.

void submit(Class<? extends Runnable> actionClass, Action<? super WorkerConfiguration> configAction)

Note: This method is incubating and may change in a future version of Gradle.

Submits a piece of work to be executed asynchronously. Execution of the work may begin immediately. Work configured with IsolationMode.PROCESS will execute in an idle daemon that meets the requirements set in the WorkerConfiguration. If no idle daemons are available, a new daemon will be started. Any errors will be thrown from WorkerExecutor.await() or from the surrounding task action if WorkerExecutor.await() is not used.