当前位置:网站首页>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
边栏推荐
猜你喜欢

【C语言】十进制数转换成二进制数

PyTorch nn. Full analysis of RNN parameters

Read the Flink source code and join Alibaba cloud Flink group..

初始JDBC 编程

Brush questions --- binary tree --2

(C language) input a line of characters and count the number of English letters, spaces, numbers and other characters.

Addition, deletion, modification and query of MySQL table (Advanced)

基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)

Applet link generation

Take you ten days to easily finish the finale of go micro services (distributed transactions)
随机推荐
全链路压测
(C language) octal conversion decimal
甜心教主:王心凌
conda常用命令汇总
CDA数据分析——AARRR增长模型的介绍、使用
Performance tuning project case
[C language] Yang Hui triangle, customize the number of lines of the triangle
自然语言处理系列(三)——LSTM
Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law
【C语言】杨辉三角,自定义三角的行数
史上最易懂的f-string教程,收藏这一篇就够了
Multiply LCA (nearest common ancestor)
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
Brush questions --- binary tree --2
Go学习笔记—多线程
drools执行String规则或执行某个规则文件
还不会安装WSL 2?看这一篇文章就够了
ORB-SLAM2不同线程间的数据共享与传递
Leetcode122 the best time to buy and sell stocks II
Filtre de profondeur de la série svo2