当前位置:网站首页>Drools terminates the execution of other rules after executing one rule
Drools terminates the execution of other rules after executing one rule
2022-07-02 12:14:00 【huan_ one thousand nine hundred and ninety-three】
List of articles
1、 background
In the process of our development , Maybe a scenario needs to write multiple rules , But some rules and other rules are mutually exclusive . That is, when a rule is established , Whether the rest of the rules are true or not , The rest of the rules are not enforced . So how to deal with this scenario ?
2、 demand
Suppose we have three rules rule-01、rule-02 and rule-03, When rule-02 After execution , that rule-03 Execution must be terminated .
3、 Implementation scheme
1、 adopt Fact Judge
When rule-02 After rule execution , modify Fact A property in , Setup rule executed , If subsequent rules are found to have been executed, they will not be executed .
2、 Judge by global variables
stay drools Use global variables to judge .
3、 adopt halt Method
When we're in drl Call in file drools.halt() After the method , It will immediately terminate the rules behind it , That is, the latter rules are not implemented .
Here we pass halt Method to implement .
4、 To achieve the above
4.1 drl Documentation
package rules
/** demand : stay "rule-01" and "rule-02" After the rule is executed , Termination Rules "rule-03" Implementation */
rule "rule-01"
salience 3
when
then
System.out.println(drools.getRule().getName());
end
rule "rule-02"
salience 2
when
then
System.out.println(drools.getRule().getName());
// Terminate below "rule-03" Execution of rules
drools.halt();
end
rule "rule-03"
salience 1
when
then
System.out.println(drools.getRule().getName());
end
The above rules are relatively simple , adopt salience Set the priority of the rule , The higher the value, the higher the priority .when There are no conditions behind , Description rules will be through pattern matching , That is, it is possible to execute . however rule-02 Regular then Some have drools.halt(), explain , After the rule is executed , The rule activated after it needs to be terminated .
4.2 Running results
rule-01
rule-02
You can see rule-03 No output , This means that the rule has been terminated .
5、 Complete code
https://gitee.com/huan1993/spring-cloud-parent/tree/master/drools/drools-termination-rule
边栏推荐
- Leetcode209 subarray with the smallest length
- PyTorch中repeat、tile与repeat_interleave的区别
- Read the Flink source code and join Alibaba cloud Flink group..
- 计算二叉树的最大路径和
- 自然语言处理系列(二)——使用RNN搭建字符级语言模型
- Brush questions --- binary tree --2
- Pytorch builds LSTM to realize clothing classification (fashionmnist)
- Differences between nodes and sharding in ES cluster
- Map和Set
- 机械臂速成小指南(七):机械臂位姿的描述方法
猜你喜欢

CDH6之Sqoop添加数据库驱动

CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节

自然语言处理系列(三)——LSTM

Jenkins voucher management

mysql表的增删改查(进阶)

MSI announced that its motherboard products will cancel all paper accessories

Go learning notes - multithreading

CDA data analysis -- Introduction and use of aarrr growth model

刷题---二叉树--2

Deep understanding of NN in pytorch Embedding
随机推荐
drools执行String规则或执行某个规则文件
String palindrome hash template question o (1) judge whether the string is palindrome
Dynamic debugging of multi file program x32dbg
Map和Set
MySQL indexes and transactions
PyTorch中repeat、tile与repeat_interleave的区别
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
drools决策表的简单使用
MSI announced that its motherboard products will cancel all paper accessories
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Brush questions --- binary tree --2
Map and set
堆(優先級隊列)
Uniapp uni list item @click, uniapp uni list item jump with parameters
深入理解PyTorch中的nn.Embedding
[old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
Jenkins用户权限管理
drools执行指定的规则
Lombok common annotations