更新了* .drl但更改未生效

时间:2014-09-24 06:23:40

标签: java drools

当编译器读取* .drl文件或哪行代码正在读取* .drl并且我想在程序执行时更新* .drl我是否会对程序产生影响?

public static void main(String[] args) throws InterruptedException {
    KnowledgeBase kbase = createKnowledgeBase();
    StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();
    Account account = new Account();
    account.setBalance(99);
    account.setId("N1");
    Account account2 = new Account();
    account2.setBalance(12);
    account2.setId("N2");
    session.insert(account);
    session.insert(account2);

    session.fireAllRules();
}

private static KnowledgeBase createKnowledgeBase() throws InterruptedException {
    KnowledgeBuilder builder = KnowledgeBuilderFactory
            .newKnowledgeBuilder();
    //File accountRules = new File("rules.drl");
    System.out.println("**Before Thread****");
    Thread.sleep(50000);
    System.out.println("***After Theread****");
    builder.add(ResourceFactory.newClassPathResource("com/iton/rules/rules.drl"), ResourceType.DRL);
    if (builder.hasErrors()) {
        throw new RuntimeException(builder.getErrors().toString());
    }

    KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
    knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
    return knowledgeBase;
}

}

0 个答案:

没有答案