当前位置:网站首页>Drools executes string rules or executes a rule file
Drools executes string rules or executes a rule file
2022-07-02 12:14:00 【huan_ one thousand nine hundred and ninety-three】
1、 background
Here we mainly record 2 A small knowledge point , Prevent forgetting later .
1、 How to be in drools Execute a drl file .
2、 If our rule is a String String of type , So how to implement .
2、 Realization
2.1 Execute specified drl file
KieHelper kieHelper = new KieHelper();
// Get the specified drl file
Resource resource = ResourceFactory.newClassPathResource("rules/alway-rule.drl", "UTF-8");
kieHelper.addResource(resource,ResourceType.DRL);
KieBase kieBase = kieHelper.build();
KieSession kieSession = kieBase.newKieSession();
kieSession.fireAllRules();
kieSession.dispose();
2.2 perform String The rules
String drl = "package rules\n" +
"\n" +
"rule \"rule-01\"\n" +
" when\n" +
" $i: Integer()\n" +
" then \n" +
" System.out.println(\" The rules :[\"+drools.getRule().getName()+\"] perform , The value existing in the rule memory is :\"+$i);\n" +
"end";
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(drl, ResourceType.DRL);
// establish KieBase It's a costly one
KieBase kieBase = kieHelper.build(EqualityBehaviorOption.IDENTITY);
System.out.println(kieBase);
// establish KieSession The cost is small
KieSession kieSession = kieBase.newKieSession();
kieSession.insert(123);
kieSession.fireAllRules();
kieBase.removeRule("rules", "rule-01");
kieSession.insert(456);
kieSession.fireAllRules();
kieSession.dispose();
It should be noted that KieBase The creation cost of is very large , Therefore, if you really want to use the necessary cache in this way .
3、 Complete code
边栏推荐
- lombok常用注解
- Gaode map test case
- Day12 control flow if switch while do While guessing numbers game
- Filtre de profondeur de la série svo2
- From scratch, develop a web office suite (3): mouse events
- 小程序链接生成
- CDA数据分析——AARRR增长模型的介绍、使用
- 计算二叉树的最大路径和
- (C语言)3个小代码:1+2+3+···+100=?和判断一个年份是闰年还是平年?和计算圆的周长和面积?
- 5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
猜你喜欢

Larvel modify table fields

自然语言处理系列(三)——LSTM

Lekao: contents of the provisions on the responsibility of units for fire safety in the fire protection law

HR wonderful dividing line

排序---

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

记录一下MySql update会锁定哪些范围的数据

Deep understanding of NN in pytorch Embedding

conda常用命令汇总

Natural language processing series (I) -- RNN Foundation
随机推荐
CDA数据分析——Excel数据处理的常见知识点归纳
Input a three digit number and output its single digit, ten digit and hundred digit.
Sort---
Leetcode topic [array] -540- single element in an ordered array
Orb-slam2 data sharing and transmission between different threads
自然语言处理系列(三)——LSTM
MySQL与PostgreSQL抓取慢sql的方法
LeetCode—剑指 Offer 37、38
Leetcode209 长度最小的子数组
【C语言】杨辉三角,自定义三角的行数
初始JDBC 编程
conda常用命令汇总
Multiply LCA (nearest common ancestor)
MySQL indexes and transactions
Lombok common annotations
drools中then部分的写法
Leetcode922 按奇偶排序数组 II
寻找二叉树中任意两个数的公共祖先
字符串回文hash 模板题 O(1)判字符串是否回文
Go learning notes - multithreading