-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActivationRuleGroup and ConditionalRuleGroup not thread safe #320
Comments
Thank you! Indeed, So I think we just need to document these classes as being non thread-safe. Do you agree? Otherwise, I'm open to other options if any. BTW, have you tried to use spring's |
Thanks for your quick reply. Yes, thread scope for the rule beans would work. But the way that I (like to) look at your framework is that it is composed of two main concepts:
So conceptually I expect the rules to be stateless and able to be instatiated as singletons. When something in the framework breaks with that expectation, I would indeed at least like to have that documented. To make the
|
You nailed it, this is explained in FAQ 6. All subclasses of
As you mentioned, this breaks the whole evaluate-execute model and things like
While this might work, it will "pollute" the
The rules engine should not be aware of the Do you agree? I suggest to document those classes as being non thread-safe. wdyt? |
Hi, I couldn't find a clean way to make composite rules thread-safe, so I documented them as being thread-unsafe. You can try to use spring's thread scope, otherwise create a custom composite rule by using one of the options you mentioned. Thank you for raising this anyway! |
Thanks for clarifying and updating the FAQ. |
I really like bas-jan's point of view around how he looks at your framework. Question for the team, what if you implemented a rule that instantiates (on creation) a RuleEngine internally, which could manage a group of rules. The facts passed to the "execute" method of this rule would simply fire the new rule engine. Would that make sense to create a thread safe "grouped" rule? You could set preferences to mimic your desired outcome. |
First of all, thanks for a great framework.
While looking into using the
CompositeRule
implementations, I noticed that theActivationRuleGroup
andConditionalRuleGroup
are not thread-safe, since they have a state based on currentFacts
.The
ActivationRuleGroup
has a fieldselectedRule
which is set in theevaluate
method, and is therefore in principle based on the current state ofFacts
.The same holds for the
ConditionalRuleGroup
, where the fieldsuccessfulEvaluations
is also determined inevaluate
.In my case, I define my rules in a Spring context as singleton beans using
@Component
. That means that theseCompositeRule
classes cannot be used in such an application. This is especially problematic in a web application with multiple threads handling different concurrent HTTP requests.The text was updated successfully, but these errors were encountered: