Drools 流口水:计时器与持续时间属性
Drools’表示计时器属性现在比持续时间更受欢迎: 规则现在支持基于时间间隔和cron的计时器,这将替换现在不推荐使用的duration属性 但我发现这样的规则行不通:Drools 流口水:计时器与持续时间属性,drools,Drools,Drools’表示计时器属性现在比持续时间更受欢迎: 规则现在支持基于时间间隔和cron的计时器,这将替换现在不推荐使用的duration属性 但我发现这样的规则行不通: rule "Expired auth" timer(int: 5s) when $auth : Authorized() $noauth : NotAuthorized() then retract($auth); retract($
rule "Expired auth"
timer(int: 5s)
when
$auth : Authorized()
$noauth : NotAuthorized()
then
retract($auth);
retract($noauth);
end
因为当它第一次被评估时,所有的事实都被删除了,并且规则不会按预期的那样被安排。
但我发现,具有duration属性的规则可以正常工作:
rule "Expired auth"
duration(5s)
...
end
那么有没有办法通过定时器来实现呢?duration被映射到一个interval timer,所以它们的工作原理是一样的。你的问题可能在其他地方
请参见第176行file.drl
rule "address should be in"
timer(int: 5s 2s) //fire after 5s and will be continue every 2s untill the sleep time out.
when
$address: Address(postcode != null)
then
System.out.println(hello("rule is fired...."));
end
java代码
// Active Mode
KieSessionConfiguration config = KieServices.Factory.get().newKieSessionConfiguration();
config.setOption( ClockTypeOption.get("realtime") );
final KieSession session = kbase.newKieSession( config, null );
session.setGlobal( "myGlobalList", list);
new Thread(new Runnable() {
public void run() {
session.fireUntilHalt();
}
}).start();
session.insert(address);
Thread.sleep(30000L);
System.out.println("end:"+ list);
session.halt();
session.dispose();
创建了一些独立的测试,看不出有什么不同,您是对的,嗯。:)你的答案只是密码。请添加一些解释?@A.sun这篇文章是关于
定时器
与持续时间
的,它们是相同的。问题出在我的逻辑上。