mswiderski / jbpm-examples

Various examples of jBPM 5
76 stars 185 forks source link

Drools concurrent issues #9

Open zhangwei22 opened 7 years ago

zhangwei22 commented 7 years ago

Hello, I encountered the same problem with him about concurrency. This is the url to this question. https://developer.jboss.org/message/829335#829335 I use thread to run drools,and version is 6.5.0.Final. This will cause a calculation error. Looked at your answer, I used threadLocal to create kieSession. The results of the test were very successful. But I would like to know if there is a better solution to solve this problem. This is part of the code:

@Component
@Scope("prototype")
public class ThreadLocalUtils {

    /**
     * @function getKieSession
     */
    public KieSession getKieSession(ThreadLocal<KieSession> tl, String kSessionName) {
        KieSession kieSessionFirstLoan = null;
        try {
            KieServices kieServices = KieServices.Factory.get();
            KieContainer kContainer = kieServices.getKieClasspathContainer();
            kieSessionFirstLoan = kContainer.newKieSession(kSessionName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        KieSession c = tl.get();
        if (null == c)
            tl.set(kieSessionFirstLoan);
        return tl.get();
    }

}

Thanks & Regards. zhangwei

vedantkekan commented 3 years ago

Hello, any update on this issue?

This will cause a calculation error.

Do you mean rules were not executed as expected?