Execution#

How Project#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#

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#

public static Execution sequential()

Scores one candidate after another on the calling thread. It's what Project#evaluate uses.

Returns: an Execution with isParallel == false.

parallel#

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.

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.

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);
    }
  }
}