1
votes

My rules in a drl file will return 1 or more String values back to the calling program.

Right now the way I do that is via global variables as below

global java.util.List<String> statuses;

The calling program will pass it an empty ArrayList() and within my rules, I'll add the String values into the List. Finally, my calling program will retrieve the statuses list that might contain zero or many String items in the list as below

session.getGlobal("statuses")

But in the drools user guide, it said that it's not recommended that rules should change values of the global variables.

Are global variables the best way to return values back to the calling program? If not, what's the best way please? I have to deal with concurrency in my web application as well so I'm looking for the best way to return values back to the calling program for concurrency as well.

Thanks

1

1 Answers

1
votes

There is nothing wrong with changing the value of a global variable in the code within the consequence ("right hand side") of a rule. What you describe is one of standard use cases for globals.

What the author of the Drools user guide (please add the exact reference!) meant is that changes of a global that is used in the condition ("left hand side") of a rule are not considered in the (re-)evaluation of these conditions. Therefore, this is to be avoided.

As for concurrency: Use a properly synchronized List object as a global.