Package org.gradle.workers
Interface WorkerExecutor
-
public 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
Work should be submitted with a
WorkAction
class representing the implementation of the unit of work and an action to configure the parameters of the unit of work (viaWorkParameters
).workerExecutor.noIsolation().submit(MyWorkActionImpl.class) { MyWorkParameters parameters -> parameters.inputFile = project.file('foo') parameters.outputFile = project.layout.buildDirectory.file('bar') }
An instance of the executor can be injected into a task by annotating a public constructor or property getter method with
javax.inject.Inject
.- Since:
- 3.5
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
await()
Blocks until all work associated with the current build operation is complete.WorkQueue
classLoaderIsolation()
Creates aWorkQueue
to submit work for asynchronous execution with an isolated classloader.WorkQueue
classLoaderIsolation(Action<? super ClassLoaderWorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution with an isolated classloader and the requirements specified in the suppliedClassLoaderWorkerSpec
.WorkQueue
noIsolation()
Creates aWorkQueue
to submit work for asynchronous execution with no isolation.WorkQueue
noIsolation(Action<? super WorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution with no isolation and the requirements specified in the suppliedWorkerSpec
.WorkQueue
processIsolation()
Creates aWorkQueue
to submit work for asynchronous execution in a daemon process.WorkQueue
processIsolation(Action<? super ProcessWorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution in a daemon process.
-
-
-
Method Detail
-
noIsolation
WorkQueue noIsolation()
Creates aWorkQueue
to submit work for asynchronous execution with no isolation.- Since:
- 5.6
-
classLoaderIsolation
WorkQueue classLoaderIsolation()
Creates aWorkQueue
to submit work for asynchronous execution with an isolated classloader.- Since:
- 5.6
-
processIsolation
WorkQueue processIsolation()
Creates aWorkQueue
to submit work for asynchronous execution in a daemon process. Work will execute in an idle daemon, if available. If no idle daemons are available, a new daemon will be started.- Since:
- 5.6
-
noIsolation
WorkQueue noIsolation(Action<? super WorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution with no isolation and the requirements specified in the suppliedWorkerSpec
.- Since:
- 5.6
-
classLoaderIsolation
WorkQueue classLoaderIsolation(Action<? super ClassLoaderWorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution with an isolated classloader and the requirements specified in the suppliedClassLoaderWorkerSpec
.- Since:
- 5.6
-
processIsolation
WorkQueue processIsolation(Action<? super ProcessWorkerSpec> action)
Creates aWorkQueue
to submit work for asynchronous execution in a daemon process. Work will execute in an idle daemon matching the requirements specified in the suppliedProcessWorkerSpec
, if available. If no idle daemons are available, a new daemon will be started.- Since:
- 5.6
-
await
void await() throws WorkerExecutionException
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.
-
-