Drools6.4简单应用之规则的优先级

1.salience

说明:指定规则的顺序,默认为0

demo:

 

package u51.test.student;

import u51.test.student.Student;



rule "student"
    salience -1
    no-loop
    when
        s:Student()
    then
        System.out.println("0.0.1");

end



rule "student-1"
    salience 1
    no-loop
    when
        s:Student()
    then
        System.out.println("0.0.2");
end


结果:会先输出0.0.1,在输出0.0.2

 

2.agenda-group

说明:议程组,可以为规则指定议程组,然后指定议程组的先后执行顺序
demo
规则文件:
package u51.test.person;


import u51.test.person.Person;



rule "test"
  agenda-group "test"
no-loop
     when
        p : Person()
     then
        System.out.println("1.0.1");
end




rule "test-1"
      agenda-group "test-1"
no-loop
     when
        p : Person()
     then
        System.out.println("1.0.2");
end
AgendaTest.java
/**
 * caicongyang.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.caicongyang.drools.drools;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.Agenda;

import u51.test.person.Person;

/**
 * Agenda group test case:优先执行的规则
 * @author caicongyang1
 * @version id: Test, v 0.1 16/10/18 上午11:41 caicongyang1 Exp $$
 */
public class AgendaTest {

    static KieSession getSession() {
        KieServices ks = KieServices.Factory.get();
        KieContainer kc = ks.getKieClasspathContainer();
        return kc.newKieSession("personKiesession");
    }

    public static void main(String[] args) {

        KieSession kSession = getSession();
        Agenda agenda = kSession.getAgenda();
        agenda.getAgendaGroup("test").setFocus();
        agenda.getAgendaGroup("test-1").setFocus();
        Person fact = new Person();
        kSession.insert(fact);
        kSession.fireAllRules();
        kSession.dispose();

    }
}
执行结果:
Drools6.4简单应用之规则的优先级_第1张图片
 

 

 

 

 

 

 
  

你可能感兴趣的:(drools)