Hello all,

I've been reading up about drool-spring integration and have put together a simple project that wires together a KnowledgeBase and KnowledgeSession as follows : 

<drools:resource id="GroupUnit" type="DRL"

source="file:/Users/drools/drools-spring-test/src/Rules/drls/GroupUnit.drl" />

<drools:resource id="GradeUnit" type="DRL"

source="file:/Users/drools/drools-spring-test/src/Rules/drls/GradeUnit.drl"" />

<drools:resource id="EvaluateUnit" type="DRL"

source="file:/Users/drools/drools-spring-test/src/Rules/drls/EvaluateUnit.drl"" />

<drools:grid-node id="node1" />

<drools:kbase id="kbase1" node="node1">

<drools:resources>

<drools:resource ref="GroupUnit" />

<drools:resource ref="GradeUnit" />

<drools:resource ref="EvaluateUnit" />

</drools:resources>

</drools:kbase>

<drools:ksession id="ksession" type="stateful" kbase="kbase1"

node="node1" />


Then in my Controller call, I 'AutoWire' in the StatefulKnowledgeSession as follows :

@Controller

@RequestMapping( value = "foo" )

final class FooController{

 

   @Autowired

   StatefulKnowledgeSession ksession;

   

   @RequestMapping(  method = RequestMethod.GET )

   @ResponseBody

   public String evaluateUnit() {

   

Unit unit = new Unit("030", "502", "C", "9484", "45", new String[] {},

null);

   

  if (ksession != null) {

  ksession.fireAllRules();

  ksession.insert(unit);

  ksession.fireAllRules();

  return "<UnitCategory>" + unit.getUnitCategory() + "</UnitCategory>";

  }

  else

  return "<message> stateful session is null</message>";

   }


The main question that I have is that – is this solution thread-safe ? From what I understand of spring is that beans configured without any additional qualifiers are inherently singletons. And when deployed in a multi-theaded container like tomcat, Spring assumes that the beans being severed up a thread-safe. So from I have read is that KnowledeSessions are inherently not thread safe. So putting the 2 together, I leaning towards the assessment that this above solution is NOT thread safe and that if I do want it to be thread safe I should set the StatefulKnowledgeSession to 'prototype' and not leave it as a singleton.

Please let me know if I'm missing anything in my assessment here !

Thanks in advance,
Gurvinder




This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, please note that you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.