当前位置:网站首页>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
边栏推荐
- H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
- PyTorch中repeat、tile与repeat_interleave的区别
- kubeadm join时出现错误:[ERROR Port-10250]: Port 10250 is in use [ERROR FileAvailable--etc-kubernetes-pki
- Le tutoriel F - String le plus facile à comprendre de l'histoire.
- drools中then部分的写法
- [QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
- Dynamic debugging of multi file program x32dbg
- Depth filter of SvO2 series
- 【工控老马】西门子PLC Siemens PLC TCP协议详解
- 堆(优先级队列)
猜你喜欢

Deep understanding of NN in pytorch Embedding

二分刷题记录(洛谷题单)区间的甄别

Jenkins用户权限管理

YYGH-BUG-04

HR wonderful dividing line

寻找二叉树中任意两个数的公共祖先

mysql索引和事务

Natural language processing series (I) -- RNN Foundation

How does Premiere (PR) import the preset mogrt template?

From scratch, develop a web office suite (3): mouse events
随机推荐
AI中台技术调研
On data preprocessing in sklearn
史上最易懂的f-string教程,收藏这一篇就够了
机械臂速成小指南(七):机械臂位姿的描述方法
XSS labs master shooting range environment construction and 1-6 problem solving ideas
Depth filter of SvO2 series
Post request body content cannot be retrieved repeatedly
Go learning notes - go based interprocess communication
ES集群中节点与分片的区别
kubeadm join时出现错误:[ERROR Port-10250]: Port 10250 is in use [ERROR FileAvailable--etc-kubernetes-pki
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
Leetcode122 买卖股票的最佳时机 II
还不会安装WSL 2?看这一篇文章就够了
Dynamic debugging of multi file program x32dbg
Leetcode14 longest public prefix
[C language] convert decimal numbers to binary numbers
Sub thread get request
jenkins 凭证管理
Leetcode922 按奇偶排序数组 II
记录一下MySql update会锁定哪些范围的数据