问题
We used Drools kieSessions in our project. Many threads can create new kieSession. Sometimes thread can hang while creating session. Hence the question:
Firstly
- is kieContainer.newKieSession thread-safe operation?
- Can the reason of hanging be a dirty writing or reading the collection of kie sessions or something like that?
回答1:
As I checked in practice
newKieSession
isn't thread-safe operation.
回答2:
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.
来源:https://stackoverflow.com/questions/25807390/is-newkiesession-thread-safe