[id='batch-solving-con_{context}']
= Batch solving problems

Batch solving is solving multiple data sets in parallel. Batch solving is particularly useful overnight:

* There are typically few or no problem changes in the middle of the night.
Some organizations enforce a deadline, for example, _submit all day off requests before midnight_.
* The solvers can run for much longer, often hours, because nobody is waiting for the results and CPU resources are often cheaper.
* Solutions are available when employees arrive at work the next working day.


.Procedure
To batch solve problems in parallel, limited by `parallelSolverCount`,
call `solve(...)` for each data set created the following class:

[source,java,options="nowrap"]
----
public class TimeTableService {

    private SolverManager<TimeTable, Long> solverManager;

    // Returns immediately, call it for every data set
    public void solveBatch(Long timeTableId) {
        solverManager.solve(timeTableId,
                // Called once, when solving starts
                this::findById,
                // Called once, when solving ends
                this::save);
    }

    public TimeTable findById(Long timeTableId) {...}

    public void save(TimeTable timeTable) {...}

}
----
