JBirch
JBirch

Reputation: 649

Salience in drools

What is the outcome of several rules having the same salience? Is their order of execution just the order that they're listed in, or is that behaviour undefined - that is, are they checked in arbitrary order? I can't seem to find documentation of how this is handled internally.

Upvotes: 3

Views: 14351

Answers (3)

EGR
EGR

Reputation: 21

The Rete algorithm used recency and specificity of conditions.

Upvotes: 2

Steven Herod
Steven Herod

Reputation: 764

My experience with Drools 5.1 is that it's last in, first out. That is, the rule defined last in your drl will be executed first.

But yes, relying on such behavior wouldn't be the best idea :)

Upvotes: 1

Michael Neale
Michael Neale

Reputation: 19468

The short answer is that you shouldn't rely on the order of rules firing of the same salience - if they are "in conflict" (ie both are eligible to fire). Rules with no salience are just salience of zero, BTW.

Of course it is deterministic - its just that the algorithm is subject to change between versions (not very likely though).

This is under the general area of "conflict resolution" and much has been written about it. I can't find a current article on Drools strategy - but I believe most of it is "recency" - ie the most recently modified/inserted fact "wins" - or rather the rules that refer to the most recent fact will win. If after all that it can't decide - it is usually the order in which they rules are loaded (which usually co-incides with how they are written in the file). If you have to have an order - use salience, or use rule-flow or similar, best not to second guess how it will work.

Upvotes: 13

Related Questions