Package org.optaplanner.core.impl.solver

## Class DefaultSolverJob<Solution_,​ProblemId_>

- java.lang.Object
- - org.optaplanner.core.impl.solver.DefaultSolverJob<Solution_,​ProblemId_>

- Type Parameters:
    `Solution_` - the solution type, the class with the `PlanningSolution` annotation
    `ProblemId_` - the ID type of a submitted problem, such as `Long` or `UUID`.
  All Implemented Interfaces:
    `Callable<Solution_>`, `SolverJob<Solution_,​ProblemId_>`

      public final class DefaultSolverJob<Solution_,​ProblemId_>
      extends Object
      implements SolverJob<Solution_,​ProblemId_>, Callable<Solution_>

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultSolverJob​(DefaultSolverManager<Solution_,​ProblemId_> solverManager, Solver<Solution_> solver, ProblemId_ problemId, Function<? super ProblemId_,​? extends Solution_> problemFinder, Consumer<? super Solution_> finalBestSolutionConsumer, BiConsumer<? super ProblemId_,​? super Throwable> exceptionHandler)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Solution_` | `call()` |
    `Solution_` | `getFinalBestSolution()` | Waits if necessary for the solver to complete and then returns the final best `PlanningSolution`.
    `ProblemId_` | `getProblemId()` |
    `SolverStatus` | `getSolverStatus()` | Returns whether the `Solver` is scheduled to solve, actively solving or not.
    `Duration` | `getSolvingDuration()` | Returns the `Duration` spent solving since the last start.
    `void` | `setFuture​(Future<Solution_> future)` |
    `void` | `terminateEarly()` | Terminates the solver or cancels the solver job if it hasn't (re)started yet.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultSolverJob

          public DefaultSolverJob​(DefaultSolverManager<Solution_,​ProblemId_> solverManager,
                                  Solver<Solution_> solver,
                                  ProblemId_ problemId,
                                  Function<? super ProblemId_,​? extends Solution_> problemFinder,
                                  Consumer<? super Solution_> finalBestSolutionConsumer,
                                  BiConsumer<? super ProblemId_,​? super Throwable> exceptionHandler)

  - ### Method Detail

    - #### setFuture

          public void setFuture​(Future<Solution_> future)

    - #### getProblemId

          public ProblemId_ getProblemId()

      Specified by:
        `getProblemId` in interface `SolverJob<Solution_,​ProblemId_>`
      Returns:
        never null, a value given to `SolverManager.solve(Object, Function, Consumer)` or `SolverManager.solveAndListen(Object, Function, Consumer)`

    - #### getSolverStatus

          public SolverStatus getSolverStatus()

      Description copied from interface: `SolverJob`
      Returns whether the `Solver` is scheduled to solve, actively solving or not.

      Returns `SolverStatus.NOT_SOLVING` if the solver already terminated.

      Specified by:
        `getSolverStatus` in interface `SolverJob<Solution_,​ProblemId_>`
      Returns:
        never null

    - #### call

          public Solution_ call()

      Specified by:
        `call` in interface `Callable<Solution_>`

    - #### terminateEarly

          public void terminateEarly()

      Description copied from interface: `SolverJob`
      Terminates the solver or cancels the solver job if it hasn't (re)started yet.

      Does nothing if the solver already terminated.

      Waits for the termination or cancellation to complete before returning. During termination, a `bestSolutionConsumer` could still be called (on a consumer thread), before this method returns.

      Specified by:
        `terminateEarly` in interface `SolverJob<Solution_,​ProblemId_>`

    - #### getFinalBestSolution

          public Solution_ getFinalBestSolution()
                                         throws InterruptedException,
                                                ExecutionException

      Description copied from interface: `SolverJob`
      Waits if necessary for the solver to complete and then returns the final best `PlanningSolution`.
      Specified by:
        `getFinalBestSolution` in interface `SolverJob<Solution_,​ProblemId_>`
      Returns:
        never null, but it could be the original uninitialized problem
      Throws:
        `InterruptedException` - if the current thread was interrupted while waiting
        `ExecutionException` - if the computation threw an exception

    - #### getSolvingDuration

          public Duration getSolvingDuration()

      Description copied from interface: `SolverJob`
      Returns the `Duration` spent solving since the last start. If it hasn't started it yet, it returns `Duration.ZERO`. If it hasn't ended yet, it returns the time between the last start and now. If it has ended already, it returns the time between the last start and the ending.
      Specified by:
        `getSolvingDuration` in interface `SolverJob<Solution_,​ProblemId_>`
      Returns:
        the `Duration` spent solving since the last (re)start, at least 0