Scheduling a Project#
This guide shows how to run the scheduler: when the one-shot Engine.schedule is enough and when to keep a Project. It also covers what the solve options change, how forward and backward planning place tasks, what "converged" means in a result, and how to run solves off a request thread.
How scheduling works#
There are two entry points, and they run the same planner:
Engine.schedule(data, options)takes aProjectDatasnapshot, schedules it once and returns aScheduleResult. Nothing is kept after the call. It's a shortcut fornew Project().solve(data, options).Project#solve(data, options)does the same work on a long-livedProject. The project keeps the scheduled dates as its accepted baseline, so later calls can edit, preview, level and evaluate against it.
Every solve goes through the same steps. The engine deep-copies the snapshot, imports it into its own normalized model and validates it. It builds the scheduling graph from links and summaries, checks for dependency cycles and works out the scope: the whole project, or one branch with subtree. Then the planner runs until the dates stop changing. The result lists only what moved.
A few rules shape what you get back:
- Updates are sparse.
result.updatesholds oneMutationper task whose dates changed, and only the changed fields are set; the others arenull. Write them back into your own model. To get every task's dates, setincludeUnchanged. - Problems are data, not exceptions. Conflicts, cycles, dropped input and non-convergence come back inside
ScheduleResult. A call throws only for invalid input (InputException) or for a call that doesn't fit the project's state (ProjectException). Both are unchecked. See Error handling. - Some tasks never move. Tasks with
autoScheduling = false, unscheduled tasks and completed tasks (useProgresswithprogress == 1) stay where they are. That's how you lock work in place. - Calls are synchronous and CPU-only. There's no I/O, no clock and no
CompletableFuturein the API. See Blocking calls.
One-shot scheduling#
Use Engine.schedule in batch jobs, request handlers and scripts that schedule a snapshot and throw it away.
;
;
Task 2 has to wait for task 1, so it's the only update: task 2: 2026-08-12 08:00 .. 2026-08-17 08:00. Task 1 is already where it belongs and isn't reported. The link uses the default type FS with no lag. The default "global" calendar works Mon-Fri, 08:00-12:00 and 13:00-17:00, which is why the dates skip the weekend.
Engine.schedule never changes the data you pass in. It throws InputException when validation rejects the snapshot, and NullPointerException for a null argument.
Solving a project#
Keep a Project when the plan lives on: an editor backend with one project per open document, or a service that applies edits over time.
;
;
This prints same object: true, then task 1: 2026-08-10 08:00 .. 2026-08-14 08:00 and task 2: 2026-08-14 08:00 .. 2026-08-19 08:00.
The two forms of solve do different jobs:
solve(data, options)deep-copies the replacement data, validates it, schedules it and accepts the dates as the new baseline. Use it on the first load and to resync the whole project. Later changes to yourProjectDataobject don't reach the project. If validation fails, you get anInputException, and the previous state and cached result stay as they were.solve(null, options)schedules the current state. After anapplyit plans the edits. Tasks the edit touched (task 1 above) are reported too, even when the planner leaves them where the edit put them. On a clean project with equal options, it returns the cached result without planning again.
The cache key is the whole SolveOptions, compared by value. That's why a fresh new SolveOptions() hits the cache in the example above. Calling solve(null, โฆ) with different options replans from the accepted dates. That doesn't change the data, so baselineId stays the same unless a task moves.
The cached result is the same object every time, and copies of the project share it. Treat it as read-only, or call deepClone() before you change it. After a rejected apply operation, solve(null, โฆ) throws ProjectException with code == ProjectError.NEEDS_RESYNC until you send the full data again with solve(data, โฆ). Editing is covered in Data updates.
Solve options#
SolveOptions changes what a solve schedules and what it reports. The defaults schedule the whole project and return only the moves.
;
;
The loop prints 1 Preferred{}, 2 Preferred{} and 3 Asap{linkId=1, sourceId=2}.
includeUnchangedalso reports tasks that didn't move, each withstartDate,endDateanddurationset. The result alone is then the full normalized date list, which is what an editor needs on first load. Unscheduled tasks are never reported. See Load all task dates.reasonsadds aReasonto each update: pushed by a predecessor link (Reason.Asap), pulled by a successor (Reason.Alap), moved with its summary block (Reason.SummaryTranslation), placed by its constraint (Reason.Constraint) or kept at its preferred date (Reason.Preferred). Read it withinstanceofpatterns or a patternswitch.analyticsasks for the critical path, slack, or both. Both are off by default. See Critical path and slack.subtreelimits the run to one task and what depends on it.new Subtree(id)setsinclusive = true, so the root task is scheduled too. The subtree applies to this call only. A scoped solve accepts only its own moves, and a later unscoped solve picks up the rest. An unknown or unscheduled subtree task is anInputExceptionat pathsubtree.task, and the cached result is kept. See Reschedule a branch.
With subtree and includeUnchanged together, the result holds every task in the subtree (with their ancestors) plus the out-of-subtree tasks that changed or were touched by an edit.
level and preview don't inherit these options. level solves with defaults first, and preview takes its own PreviewOptions.
Forward and backward planning#
By default the planner works forward: each task starts as early as its links allow. Set config.scheduleFromEnd to plan backward instead. Then each task ends as late as its successors allow, and the project is anchored at its end.
;
;
Task 2 has no successor, so projectEnd caps it and it ends at 2026-08-28 17:00. Task 1 ends where task 2 starts, on 2026-08-25 17:00.
The project bounds in SchedulingConfig act only on tasks at the open ends of the graph:
projectStart(forward) applies to tasks without predecessors. WithGapBehavior.COMPRESSit pulls them onto the project start. WithGapBehavior.PRESERVEit only raises tasks that start earlier and leaves later ones at their dates. For a task with predecessors, it's a hard floor only whenapplyConstraintsis on.projectEnd(backward) caps tasks without successors, in either gap mode. Without it, such a task keeps its current end.
A task whose constraint points the other way gets a secondary pass in the opposite direction. In a forward project with applyConstraints, an ALAP task moves as late as its successors allow:
;
;
install waits for build and starts on 2026-08-14 08:00. order moves from Monday to 2026-08-13 08:00, so it ends right when install starts.
Leveling is forward-only. Project#level rejects a project with scheduleFromEnd = true with an InputException at path config.schedule_from_end. Constraint types and summary behavior are covered in Links, constraints and summaries.
Determinism and convergence#
The same input and options always give the same result. The engine reads no clock and uses no randomness. It iterates in input order and topological order, never in hash order. That makes results safe to cache, diff and compare in tests.
The one exception is baselineId. Baseline tokens are opaque and unique only within the process, so the same data can get a different token on another run. Don't store them or compare them across runs. Take the current one from the latest solve result.
The planner runs passes until the dates stop changing. result.converged tells you whether it reached that point within config.maxIterations passes:
- An unscoped run converges in two passes by design. The second pass reproduces the first.
- A scoped run (
subtree) can need more passes, because tasks outside the scope feed into it. maxIterationsis anint, defaults to 8 and must be at least 1.0is rejected with anInputException.
;
;
converged == false isn't an error, and the result is still valid.
A dependency cycle stops the run before planning. Dates stay unchanged, updates is empty and cycles lists each unique cycle. For everything else a result carries, see Reading results.
Blocking calls#
Every call is synchronous and CPU-bound. solve and Engine.schedule return only when the schedule is done, and there's no cancellation. In a reactive server, or anywhere the calling thread must stay free, run large solves on your own executor:
;
;
;
;
;
Engine.schedule builds a fresh project for each call, so concurrent calls on separate snapshots share no project state. A Project isn't synchronized, and even copy() updates its internal sharing flags. Serialize access to one instance, or give each thread its own copy() made on one thread. See Call from async code and Share a project between threads.