This content has been marked as final. Show 3 replies
At first glance it looks to me like you are possibly over-complicating your interactions with the engine. The OPA engine can do a lot for you - and you should let it. In almost all cases, it is better to push all the data required to determine all the outputs into the engine at the start, call think() once, then read all the results out.
You should take advantage of the implicit operations that occur during the think() cycle, such as the set-based operations (minimum, maximum, sum, etc) and the inherent iteration that occurs over entity instances.
In general, the low-level control of rule/operation execution should be controlled by the rules (and the engine) and not programmatically.
In your case my advice would be to look at modeling your days of the week as entities, create 7 of them, and have the rules operate across the collection during a single think(). Assigning one of these higher-level (whole week) determinations to an individual thread would probably be a better level to do your thread management.
I agree with the previous analysis but to answer your specific question, the engine is thread safe, in fact it only exists a singleton, the rulebase is also thread safe which is excellent as it can be quite big and take a while to load. The session is not thread safe and I suspect the error you are seeing is due to multiple threads accessing the same session. It is not strictly necessary to discard the session after each cycle but creating a new one is relatively quick and this may well be the best way to ensure you don't have any data hanging around that you no longer want.