当前位置:网站首页>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
边栏推荐
- [geek challenge 2019] upload
- Addition, deletion, modification and query of MySQL table (Advanced)
- 排序---
- Input a three digit number and output its single digit, ten digit and hundred digit.
- conda常用命令汇总
- [C language] convert decimal numbers to binary numbers
- 二分刷题记录(洛谷题单)区间的甄别
- Test shift left and right
- 高德地图测试用例
- CDA数据分析——Excel数据处理的常见知识点归纳
猜你喜欢

YYGH-BUG-05

刷题---二叉树--2

Mysql database foundation

The blink code based on Arduino and esp8266 runs successfully (including error analysis)

MySQL indexes and transactions

WSL 2 will not be installed yet? It's enough to read this article

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

CDH6之Sqoop添加数据库驱动

arcgis js 4.x 地图中加入图片

(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
随机推荐
深入理解PyTorch中的nn.Embedding
[C language] convert decimal numbers to binary numbers
ThreadLocal的简单理解
mysql索引和事务
Those logs in MySQL
Yygh-9-make an appointment to place an order
lombok常用注解
Sparkcontext: error initializing sparkcontext solution
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
Map和Set
AI中台技术调研
(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
【C语言】杨辉三角,自定义三角的行数
jenkins 凭证管理
Input a three digit number and output its single digit, ten digit and hundred digit.
Performance tuning project case
Leetcode739 每日温度
JZ63 股票的最大利润
LeetCode—剑指 Offer 37、38
二分刷题记录(洛谷题单)区间的甄别