当前位置:网站首页>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
边栏推荐
- 自然语言处理系列(一)——RNN基础
- Maximum profit of jz63 shares
- Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
- Full link voltage measurement
- Those logs in MySQL
- 【工控老马】西门子PLC Siemens PLC TCP协议详解
- CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
- 初始JDBC 编程
- Differences between nodes and sharding in ES cluster
- [old horse of industrial control] detailed explanation of Siemens PLC TCP protocol
猜你喜欢

自然语言处理系列(二)——使用RNN搭建字符级语言模型

自然语言处理系列(一)——RNN基础

(C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?

堆(优先级队列)

Larvel modify table fields

Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)

AI中台技术调研

jenkins 凭证管理

Docker-compose配置Mysql,Redis,MongoDB

Test shift left and right
随机推荐
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
drools执行完某个规则后终止别的规则执行
mysql索引和事务
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
PyTorch中repeat、tile与repeat_interleave的区别
Gaode map test case
Leetcode14 最长公共前缀
Leetcode122 the best time to buy and sell stocks II
Leetcode922 sort array by parity II
Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law
Test shift left and right
小程序链接生成
求16以内正整数的阶乘,也就是n的阶层(0=<n<=16)。输入1111退出。
Codeforces 771-div2 C (trouble, permutation is not very good)
使用Sqoop把ADS层数据导出到MySQL
Deep understanding of NN in pytorch Embedding
Leetcode739 每日温度
怎样写一篇赏心悦目的英文数学论文
全链路压测
Maximum profit of jz63 shares