[Canonical page](<https://docs.dhtmlx.com/planning-engine/java/api/evaluate/execution/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Execution

How [`Project#evaluateWith`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md#evaluatewith>) scores candidates: one after another, or on worker threads. Get an instance from `Execution.sequential()` or `Execution.parallel(...)`. Both modes return the same results.

## Declaration

```java
package org.dhtmlx.plen;

public final class Execution
```

`Execution` has no public constructor. Instances are immutable.

## Fields

| Field | Type | Description |
|---|---|---|
| `isParallel` | `boolean` | `true` for an instance made by `parallel`, `false` for `sequential()`. `public final`. |
| `threads` | `Integer` | The thread count passed to `parallel`. `null` means the processor count, and it's always `null` for `sequential()`. `public final`. |

## Static methods

### sequential

```java
public static Execution sequential()
```

Scores one candidate after another on the calling thread. It's what [`Project#evaluate`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md>) uses.

**Returns**: an `Execution` with `isParallel == false`.

### parallel

```java
public static Execution parallel()
public static Execution parallel(Integer threads)
```

Scores candidates on a fixed thread pool with at most `threads` workers. Results and their order are the same as with `sequential()`. For pool size, memory use and error order, see [`Project#evaluateWith`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md#evaluatewith>).

**Parameters**

| Name | Type | Description |
|---|---|---|
| `threads` | `Integer` | Optional. The maximum number of worker threads. `null`, or the no-argument overload, uses `Runtime.getRuntime().availableProcessors()`. |

**Returns**: an `Execution` with `isParallel == true`.

**Errors**: throws `IllegalArgumentException` (unchecked) when `threads` is `0` or negative.

## Example

Score two candidates on up to four threads.

```java
import java.util.List;
import org.dhtmlx.plen.*;

public class ExecutionExample {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 8, 10, 8, 0);
    ProjectData data = new ProjectData()
        .withTasks(List.of(
            new TaskData(Id.num(1)).withStartDate(monday).withDuration(2.0)))
        .withResources(List.of(
            new ResourceData().withId(Id.str("dev1")),
            new ResourceData().withId(Id.str("dev2"))));

    Project project = new Project();
    project.solve(data, new SolveOptions());

    List<Candidate> candidates = List.of("dev1", "dev2").stream()
        .map(dev -> {
          SchedulingChanges changes = new SchedulingChanges();
          changes.assignments.add.add(new AssignmentData()
              .withId(Id.str("a-" + dev))
              .withTask(Id.num(1))
              .withResource(Id.str(dev))
              .withValue(1.0));
          return new Candidate().withId(Id.str(dev)).withChanges(changes);
        })
        .toList();

    EvaluateResult result =
        project.evaluateWith(candidates, new EvaluateOptions(), Execution.parallel(4));
    for (CandidateResult candidate : result.candidates) {
      System.out.println(candidate.id + ": cost " + candidate.cost);
    }
  }
}
```

## Related

- [`Project#evaluateWith`](<https://docs.dhtmlx.com/planning-engine/java/api/project-evaluate.md#evaluatewith>) - the call that takes an execution mode
- [`EvaluateResult`](<https://docs.dhtmlx.com/planning-engine/java/api/evaluate/evaluate-result.md>) - the result, the same in both modes
- [Evaluating alternatives](<https://docs.dhtmlx.com/planning-engine/java/resources-and-assignment/evaluating-alternatives.md#parallel-evaluation>) - when parallel evaluation pays off
- [Call from async code](<https://docs.dhtmlx.com/planning-engine/java/how-to/call-from-async-code.md>) - scoring candidates on several cores from a server
