Package org.gradle.workers
Interface WorkerExecutor
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
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') ] }
- Since:
- 3.5
-
Method Summary
-
Method Details
-
submit
void submit(Class<? extends Runnable> actionClass, Action<? super WorkerConfiguration> configAction) Submits a piece of work to be executed asynchronously. Execution of the work may begin immediately. Work configured withIsolationMode.PROCESS
will execute in an idle daemon that meets the requirements set in theWorkerConfiguration
. If no idle daemons are available, a new daemon will be started. Any errors will be thrown fromawait()
or from the surrounding task action ifawait()
is not used. -
await
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.- Throws:
WorkerExecutionException
- when a failure occurs while executing the work.
-