当前位置:网站首页>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
边栏推荐
- LeetCode—<动态规划专项>剑指 Offer 19、49、60
- Fastdateformat why thread safe
- Multiply LCA (nearest common ancestor)
- PyTorch nn.RNN 参数全解析
- Jenkins用户权限管理
- Natural language processing series (III) -- LSTM
- 求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
- 记录一下MySql update会锁定哪些范围的数据
- jenkins 凭证管理
- This article takes you to understand the operation of vim
猜你喜欢
倍增 LCA(最近公共祖先)
自然语言处理系列(二)——使用RNN搭建字符级语言模型
CDH6之Sqoop添加数据库驱动
(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
Natural language processing series (III) -- LSTM
arcgis js 4.x 地图中加入图片
ES集群中节点与分片的区别
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
Applet link generation
随机推荐
PyTorch搭建LSTM实现服装分类(FashionMNIST)
(C语言)八进制转换十进制
Leetcode14 longest public prefix
Filtre de profondeur de la série svo2
Leetcode739 daily temperature
kubeadm join时出现错误:[ERROR Port-10250]: Port 10250 is in use [ERROR FileAvailable--etc-kubernetes-pki
drools决策表的简单使用
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
Leetcode topic [array] -540- single element in an ordered array
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
FastDateFormat为什么线程安全
lombok常用注解
使用Sqoop把ADS层数据导出到MySQL
Applet link generation
LeetCode—剑指 Offer 59 - I、59 - II
mysql索引和事务
HR wonderful dividing line
post请求体内容无法重复获取
B high and beautiful code snippet sharing image generation
When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device