Skip to content
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

RulesEngine lifetime and thread-safety #580

Open
Makciek opened this issue Feb 5, 2024 · 4 comments
Open

RulesEngine lifetime and thread-safety #580

Makciek opened this issue Feb 5, 2024 · 4 comments

Comments

@Makciek
Copy link

Makciek commented Feb 5, 2024

Hello
I can't find it in docs nor in wiki, what's the advised lifetime of the RulesEngine object? Should I create it every time I need it and it will cache the compiled evaluator itself or should I create just one instance and cache it? If so is it thread-safe and I can reuse the same instance at the same time?

@abbasc52
Copy link
Contributor

abbasc52 commented Feb 7, 2024

@Makciek , it is recommended to use it as single instance to benefit from caching of compilation.

Also, it is thread safe, so you can use same instance at same time

@vanwx
Copy link

vanwx commented Feb 13, 2024

Hello, I'm curious about the thread safety of the localParam. If we aim to record the result of rule evaluation and assign it to a local parameter, could it be overwritten by other rule evaluations with different inputs?

For instance, let's say we construct a rule containing blacklist words. If the text contains any of these blacklist words, we wish to record the offensive word in the localParam and utilize it to generate the FailureMessage.

@abbasc52
Copy link
Contributor

@vanwx localParam is like a local variable in code, they do not share reference with any other rule or execution. So it should be completely thread safe

@vanwx
Copy link

vanwx commented Feb 22, 2024

@vanwx localParam is like a local variable in code, they do not share reference with any other rule or execution. So it should be completely thread safe

Yeah thanks @abbasc52 . I did write some tests and it's been safe. Also I found some examples on this repo use the localParam to store result state so it's good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants