简体   繁体   中英

is newKieSession thread-safe?

We used Drools kieSessions in our project. Many threads can create new kieSession. Sometimes thread can hang while creating session. Hence the question:

Firstly

  1. is kieContainer.newKieSession thread-safe operation?
  2. Can the reason of hanging be a dirty writing or reading the collection of kie sessions or something like that?

As I checked in practice

newKieSession

isn't thread-safe operation.

I couldn't find any explicit statement in the drools documentation, but my understanding is that the KieContainer is thread-safe and even smart enough to (somewhat silently/magically) update itself (or rather its contained KieBases).

For all practical purposes (debugging/reading the source code) I think all the KieContainer.newStatelessKieSession() and the KieContainer.newKieSession() methods are thread-safe.

I am not 100% sure about the updateToVersion() and updateDependencyToVersion() methods and whether changing the kie container through those works in parallel with the KieContainer.newStatelessKieSession() and newKieSession() methods.

In our application we managed to separate the logic of modifying your rules (and modules, bases, sessions and their configuration) from the rule evaluation (which uses the newKieSession etc methods) and things seem to be fine so far, but I'd like to understand how you came to the conclusion that it isnt thread-safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM