Claus Ibsen created CAMEL-26123:
-----------------------------------

             Summary: camel-optaplanner - with configFile a new SolverManager 
is created per exchange and never closed (thread leak), and consumers get the 
events of every CamelContext
                 Key: CAMEL-26123
                 URL: https://issues.apache.org/jira/browse/CAMEL-26123
             Project: Camel
          Issue Type: Bug
          Components: camel-optaplanner
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of flink, spring-batch and 
optaplanner (CAMEL-24961, PR #28418).

h4. 1. With configFile and no solverManager, every exchange leaks a 
SolverManager and its threads

{{OptaPlannerProducer.getSolverManager}} (main 2a465aa4814c, line 145) creates 
a new {{SolverManager}} from the {{configFile}} for each exchange when no 
{{solverManager}} is configured, and it is never closed. Checked on 
4.24.0-SNAPSHOT with the CloudBalance example: the live threads went from 16 to 
35 after 20 calls.

Proposed: create the SolverManager once per endpoint (in doStart) and close it 
in doStop.

h4. 2. Solvers and listeners are JVM-wide, keyed only by problemId

{{OptaPlannerEndpoint}} keeps the solvers and the solution listeners in static 
maps ({{SOLVERS}} and {{SOLUTION_LISTENER}}, main 2a465aa4814c, lines 41-42), 
the listeners keyed only by {{problemId}}, which defaults to 1 
({{OptaPlannerConfiguration}} line 38). A consumer in any CamelContext of the 
JVM receives the best solutions of every async producer with the same 
problemId. Checked on 4.24.0-SNAPSHOT with the CloudBalance example.

Proposed: keep the solvers and listeners per endpoint (or per CamelContext and 
solver config), not in static maps.

h4. 3. Sync mode sends no events to consumers

With {{async=false}} the producer calls {{solverManager.solve(problemId, 
body)}} ({{OptaPlannerProducer}}, main 2a465aa4814c, line 101) without a best 
solution listener, so a consumer on the same problem gets no events, unlike 
async mode. Checked on 4.24.0-SNAPSHOT with the CloudBalance example.

Proposed: also notify the consumers of the final best solution in sync mode, or 
document that consumers only work with async producers.

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to