Tôi đang thử thực hiện động cơ quy tắc Drools, tôi khá mới bắt đầu.drools: quy tắc được thực thi nhiều lần
tôi có các quy tắc sau tại chỗ trong một tập tin quy tắc duy nhất:
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
Trong StatefulKnowledgeSession tôi đi qua hai tài khoản, một với sự cân bằng 15000 khác với số dư 15,
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();
Theo tôi, kết quả mong đợi là mỗi quy tắc sẽ chỉ được kích hoạt một lần và đối tượng tương ứng sẽ được in.
Nhưng kết quả tôi nhận được là:
balance>100
15000
Samrat
balance>100
15000
Samrat
balance<100
15
Alexi
balance<100
15
Alexi
Tôi không thể hiểu tại sao từng quy tắc đang chạy hai lần ????
Bang trên! điều này cố định nó! – Samrat