我正在嘗試在Drools規則引擎上工作,我是一個初學者。drools:規則執行超過一次
我已經制定了以下規則在一個規則文件:
rule "A stand alone rule"
salience 2
no-loop
when
$account : Account()
Account($account.balance>100)
then
System.out.println("balance>100");
System.out.println($account.getBalance());
System.out.println($account.getCustomer().getName());
end
rule "A second Rule"
salience 1
no-loop
when
$account : Account()
Account($account.balance<100)
then
System.out.println("balance<100");
System.out.println($account.getBalance());
System.out.println($account.getCustomer().getName());
end
在我傳遞兩個帳戶,一個具有平衡15000另一個與平衡15 StatefulKnowledgeSession,
Account account=new Account(7l,15000l);
Account account1=new Account(5l,15l);
Customer customer = new Customer("Samrat", 28, "Sector51", account);
Customer customer1 = new Customer("Alexi", 28, "Sector50", account1);
account.setCustomer(customer);
account1.setCustomer(customer1);
session.insert(account);
session.insert(account1);
session.fireAllRules();
根據我的預期結果應該是,每個規則只能被觸發一次,並且相應的對象應該被打印。
但我得到的結果是:
balance>100
15000
Samrat
balance>100
15000
Samrat
balance<100
15
Alexi
balance<100
15
Alexi
我無法理解爲什麼每個規則運行兩次????
中邦!這固定它! – Samrat