I would have thought you could re-use the same session in a given single Thread - Session is not Thread-Safe but not unsafe to reuse.

As an aside, I wonder whether you can use a single session across all Threads if you used different Entry Points for each Thread (although you'd probably have to duplicate rules for each Entry Point so not sure the pros- out weigh the cons-). Edson, Mark?

2010/9/27 Nadav Hashimshony <nadavh@gmail.com>
My rule engine server is multi threaded.

in the server main i build a knowledgebase:

KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(droolsConf, null);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
builder.add(ResourceFactory.newFileResource("path to drools pkg", ResourceType.PKG);
       
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());

i have 10 threads that have the following code:



thread run method:


as long as a Vector has data do:

1. StatelessKnowledgeSession droolsSession= m_droolsKagent.getKnowledgeBase().newStatelessKnowledgeSession();
2. get data object  from a vector
3. create fact model from data
4. droolsSession.insert(facts);
5. droolsSession.fireAllRules();
6. do stuff with the response
7.droosSession.dispose
8.get  next object from vector.


Questions:
1. should i create each time the droolsSession? or can i resuse the same one, meaning can i create it in the Thread's constractor?

Thanks
Nadav.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users