is newKieSession thread-safe?

谁都会走 提交于 2019-12-01 23:27:47

问题


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?

回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!