Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-534

Graceful shutdown: if the Solver thread is interrupted, the Solver should terminate early

XMLWordPrintable

    • NEW
    • NEW

      The Solver thread is the thread that calls solver.solve().
      Solver threads are often part of a thread pool.

      A thread pool is normally destroyed before an app ends, to enforce a graceful shutdown.
      solve() calls that have already started won't actually stop (in a timely manner or even ever), because the contacts says that they:

      • will cancel all tasks that haven't started yet
      • interrupt the threads of all tasks that have already started

      Currently, optaplanner doesn't check Thread.interrupt() so they'll happily keep solving.

      Proposal A

      In BasicPlumbingTermination (= so in every iteration) check Thread.interrupted(). If the thread was interrupted, set it again as interrupted (as required by Java spec, see also discussion in PLANNER-402) and throw a runtime exception.

      Why not an InterruptedException? That's a checked exception, which would impact our API's badly.

      Proposal B

      Like A), but have solve() throw InterruptedException. There goes my HelloWorld example! No thanks.

      Proposal C

      Like A), but instead of throwing an exception, just behave like terminateEarly() (but still leave the thread as interrupted as required by Java spec)

            gdesmet@redhat.com Geoffrey De Smet (Inactive)
            gdesmet@redhat.com Geoffrey De Smet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: