当前位置: 首页 > news >正文

drool 7 multiThread 测试

基本信息

通过option ,使用如下代码进行设置

 //线程数量10MaxThreadsOption option=MaxThreadsOption.get(10);kieBaseConf.setOption(option);kieBaseConf.setOption(MultithreadEvaluationOption.YES);

并发是以CompositeDefaultAgenda/Rule为颗粒度来的,不同CompositeDefaultAgenda/rule在不同线程内执行 。

限制条件

在 KnowledgeBaseImpl 类 有如下代码:

private void checkMultithreadedEvaluation( RuleImpl rule ) {if (config.isMultithreadEvaluation()) {if (!rule.isMainAgendaGroup()) {disableMultithreadEvaluation( "Agenda-groups are not supported with multithread evaluation: disabling it" );} else if (rule.getActivationGroup() != null) {disableMultithreadEvaluation( "Activation-groups are not supported with multithread evaluation: disabling it" );} else if (!rule.getSalience().isDefault()) {disableMultithreadEvaluation( "Salience is not supported with multithread evaluation: disabling it" );} else if (rule.isQuery()) {disableMultithreadEvaluation( "Queries are not supported with multithread evaluation: disabling it" );}}
}

即不支持

  • agenda 分组
  • getActivationGroup
  • 优先级设置
  • Query

以下为 Agenda-groups测试,验证了上述点

09:48:08.187 [main] WARN  o.drools.core.impl.KnowledgeBaseImpl.disableMultithreadEvaluation:1010 - Agenda-groups are not supported with multithread evaluation: disabling it
[Rule name=Stateless Hello World, agendaGroup=again, salience=0, no-loop=false]
1700876888206
Always  Stateless message in thread 1,1700876888279
Always Again Stateless message in thread 1,1700876901286
Hello World again in thread 1,1700876914293
Process finished with exit code 0取消
09:47:15.242 [main] WARN  o.d.c.k.builder.impl.KieBuilderImpl.packageNameForFile:394 - File 'org/drools/learn/MultiThreadHelloWorld.drl' is in folder 'org/drools/learn' but declares package 'org.drools.examples.multiThreadHello'. It is advised to have a correspondance between package and folder names.
[Rule name=Stateless Hello World, agendaGroup=MAIN, salience=0, no-loop=false]
1700876836099
Hello World in thread 19,1700876836192
Always  Stateless message in thread 18,1700876836193
Always Again Stateless message in thread 18,1700876849220
Stateless Goodbye cruel world in thread 24,1700876862233

其它

在这里插入图片描述
在executor里面submit的是CompositeDefaultAgenda,如果多个rule的when一致,会在同一线程执行,是drools把相关when合并在一个compsite吗?

Java 代码

// private static KieSessionConfiguration kieBaseConf;public static final void main(final String[] args) {KieServices ks = KieServices.get();KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();//设置SequentialOption以提升性能kieBaseConf.setOption(SequentialOption.YES);//设置使用对象的equals函数来进行对象比较kieBaseConf.setOption(EqualityBehaviorOption.EQUALITY);//设置exception 捕获,不设置为默认使用org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandlerkieBaseConf.setOption(ConsequenceExceptionHandlerOption.get(DroolsConsequenceExceptionHandler.class));//线程数量10MaxThreadsOption option = MaxThreadsOption.get(10);kieBaseConf.setOption(option);kieBaseConf.setOption(MultithreadEvaluationOption.YES);//使用resource模式装载,参考https://zhuanlan.zhihu.com/p/519969197Resource resource =new ClassPathResource("org/drools/learn/MultiThreadNoModifyHelloWorld.drl");KieBase base = new KieHelper().addResource(resource).build(kieBaseConf);StatelessKieSession ksession = base.newStatelessKieSession();System.out.println(ksession.getKieBase().getRule("org.drools.examples.MultiThreadNoModifyExample","Stateless 4 "));ArrayList result = new ArrayList<Object>();ksession.setGlobal("list", result);KieRuntimeLogger logger= ks.getLoggers().newFileLogger(ksession, "./helloworld");System.out.println(System.currentTimeMillis());Message message = new Message();message.setMessage("Hello World");message.setStatus(10);ksession.execute(message);logger.close();}

DRL

package org.drools.examples.MultiThreadNoModifyExampleimport org.drools.learn.MultiThreadNoModifyExample.Message;global java.util.List listrule "Stateless 0  "dialect "mvel"whenm : Message( status >0 , status : status )thenSystem.out.println(   " 0 in thread " + Thread.currentThread().getId()+","+ Thread.currentThread().getName()+","+System.currentTimeMillis());Thread.sleep(13000);
endrule "Stateless 1  "dialect "mvel"whenm : Message( status >1 , status : status )thenSystem.out.println(  " 1 in thread " + Thread.currentThread().getId()+","+ Thread.currentThread().getName()+","+System.currentTimeMillis());Thread.sleep(13000);
endrule "Stateless 2  "dialect "mvel"whenm : Message( status >2 , status : status )thenSystem.out.println(  " 2 in thread " + Thread.currentThread().getId()+","+ Thread.currentThread().getName()+","+System.currentTimeMillis());Thread.sleep(13000);
endrule "Stateless 3  "dialect "mvel"whenm : Message( status >3 , status : status )thenSystem.out.println(   " 3 in thread " + Thread.currentThread().getId()+","+ Thread.currentThread().getName()+","+System.currentTimeMillis());Thread.sleep(13000);
endrule "Stateless 4  "dialect "mvel"whenm : Message( status > 4 , status : status )thenSystem.out.println(   " 4 in thread " + Thread.currentThread().getId()+","+ Thread.currentThread().getName()+","+System.currentTimeMillis());Thread.sleep(13000);
end
http://www.lryc.cn/news/245738.html

相关文章:

  • 【网安AIGC专题】46篇前沿代码大模型论文、24篇论文阅读笔记汇总
  • 如何在Simulink中使用syms?换个思路解决报错:Function ‘syms‘ not supported for code generation.
  • 论文导读 | 10月专题内容精选:人的预测
  • 深度学习18
  • Mysql数据库 18.Mysql SQL优化
  • [AutoSAR 存储] 汽车智能座舱的存储需求
  • 大数据-之LibrA数据库系统告警处理(ALM-37006 Coordinator进程异常)
  • python 列表的操作
  • Vue快速实践总结 · 上篇
  • 外汇天眼:香港监管机构对AMTD Global Markets Limited启动法律诉讼
  • OpenCV入门教程
  • 84基于matlab的数字图像处理
  • jQuery_09 事件的绑定与使用(on)
  • 详解Java中的泛型(泛型的语法,擦除机制,泛型的上界)
  • 数据结构算法-贪心算法
  • 【云备份】数据管理模块
  • C++ :const修饰成员函数
  • 论文阅读:“Model-based teeth reconstruction”
  • Web 安全之证书透明(Certificate Transparency)详解
  • 智能优化算法应用:基于蜻蜓算法无线传感器网络(WSN)覆盖优化 - 附代码
  • 【古诗生成AI实战】之二——项目架构设计
  • 动态网页从数据库取信息,然后展示。
  • 单片机学习3——数码管
  • 数据库表结构导出成Excel或Word格式
  • School training competition ( Second )
  • 深度解析 Docker Registry:构建安全高效的私有镜像仓库
  • leetcode 不同的二叉搜索树
  • 通俗易懂的spring Cloud;业务场景介绍 二、Spring Cloud核心组件:Eureka 、Feign、Ribbon、Hystrix、zuul
  • 大数据预处理技术
  • 跳表的学习记录