当前位置:网站首页>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
边栏推荐
- Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
- Larvel modify table fields
- CONDA common command summary
- Leetcode topic [array] -540- single element in an ordered array
- Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
- Time format display
- Sort---
- Deep understanding of NN in pytorch Embedding
- 堆(优先级队列)
- LeetCode—剑指 Offer 37、38
猜你喜欢

MySQL indexes and transactions

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

Sort---

机械臂速成小指南(七):机械臂位姿的描述方法

Jenkins voucher management

Applet link generation

HR wonderful dividing line

Natural language processing series (II) -- building character level language model using RNN

CDH6之Sqoop添加数据库驱动

The blink code based on Arduino and esp8266 runs successfully (including error analysis)
随机推荐
MySQL and PostgreSQL methods to grab slow SQL
[C language] convert decimal numbers to binary numbers
Repeat, tile and repeat in pytorch_ The difference between interleave
Leetcode122 买卖股票的最佳时机 II
(C语言)八进制转换十进制
post请求体内容无法重复获取
Go learning notes - go based interprocess communication
Leetcode739 每日温度
怎样写一篇赏心悦目的英文数学论文
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
Tas (file d'attente prioritaire)
Depth filter of SvO2 series
Codeforces 771-div2 C (trouble, permutation is not very good)
jenkins 凭证管理
CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
【工控老马】西门子PLC Siemens PLC TCP协议详解
还不会安装WSL 2?看这一篇文章就够了
Jenkins用户权限管理
[C language] Yang Hui triangle, customize the number of lines of the triangle
测试左移和右移