我们将按照以下方式实用地创建KIEBases并将已编译的Kiebases存储在Java映射中:
private static Map<String, KieBase> kieBaseMap = new HashMap<>();
public setKieBaseMap(String groupId,String drl){
KieHelper kieHelper = new KieHelper();
kieHelper.addContent(drl, ResourceType.DRL);
Results results = kieHelper.verify();
kieBaseMap.put(groupId,kieHelper.build());
}
StatelessKieSession buildKieSession(String ruleGroupId) {
return kieBaseMap.get(ruleGroupId).newStatelessKieSession();
}
但是如果我们再次尝试执行相同的Kiebase,则会遇到以下异常:
java.lang.NullPointerException
at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:95)
at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:71)
at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:552)
at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:538)
at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:373)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:333)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:169)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:127)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:212)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:87)
at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1067)
at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1014)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1006)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1308)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1299)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1283)
at org.drools.core.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:281)
我已经设定
drools.getWorkingMemory().getKnowledgeBase().getConfiguration().setProperty(SequentialOption.PROPERTY_NAME,"true")
按顺序执行所有规则。请帮助我为什么会收到此异常
答案 0 :(得分:0)
这看起来像个错误。您使用哪个版本的Drools?最新版本应为7.16.0.Final。如果您不使用此版本,可以尝试使用它吗?如果它在最新版本上也失败,请在https://issues.jboss.org中创建票证,最好是使用复制器。复制器可以是描述您的用例并产生异常的简单JUnit测试。
答案 1 :(得分:0)
由于我想按顺序运行议程组,因此需要在模块创建时自行设置SequentialAgendaOption.DYNAMIC:
kieSessionBuilder.setKieBaseMap(
ruleGroupId, kieHelper.build(SequentialAgendaOption.DYNAMIC, SequentialOption.YES));
然后这个问题没有出现