optaplannertimefold

Listener for Solver Status Changes with solverManager


I am implementing a Multitenancy approach to handle various datasets in parallel using a solverManager. I need to save the status of these solvers in a DB. Is there a way to trigger an event whenever the solver status changes (SOLVING_ACTIVE , NOT_SOLVING), allowing me to perform specific logic (such as updating the status in the DB)? Additionally, if this is not directly supported, would it be efficient to create my own thread that utilizes the solverManager.getSolverStatus() method? This thread would periodically check the solver status to perform necessary actions.

Thanks.


Solution

  • The SolverStatus on SolverJob is available at any point in time and it is kept up to date. But there is no mechanism to check for when it changes.

    You can catch the final best solution event, which indicates that the solver has terminated. With the other listeners, you can catch the first best solution event, indicating that the solver is running. And you can catch any exceptions, indicating failure.