<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body style="word-wrap:break-word; font-size:14px; font-family:Calibri,sans-serif">
<div>
<div>
<div style="color:rgb(0,0,0)">Hello all,</div>
</div>
</div>
<div style="color:rgb(0,0,0)"><br>
</div>
<div style="color:rgb(0,0,0)">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 :&nbsp;</div>
<div style="color:rgb(0,0,0)"><br>
</div>
<div>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span style="color:#009292"><span class="Apple-tab-span" style="white-space:pre"></span>&lt;</span><span style="color:#4b9191">drools:resource</span><span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span>&quot;GroupUnit&quot;<span style="color:#000000">
</span><span style="color:#961f8d">type</span><span style="color:#000000">=</span>&quot;DRL&quot;</p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#961f8d">source</span><span style="color:#000000">=</span>&quot;file:/Users/drools/drools-spring-test/src/Rules/drls/GroupUnit.drl&quot;<span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span><span style="color:#4b9191">drools:resource</span><span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span>&quot;GradeUnit&quot;<span style="color:#000000">
</span><span style="color:#961f8d">type</span><span style="color:#000000">=</span>&quot;DRL&quot;</p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span class="Apple-style-span"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#961f8d">source</span><span style="color:#000000">=</span>&quot;</span>file:/Users/drools/drools-spring-test/src/Rules/drls/GradeUnit.drl&quot;<span class="Apple-style-span">&quot;<span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></span></p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span><span style="color:#4b9191">drools:resource</span><span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span>&quot;EvaluateUnit&quot;<span style="color:#000000">
</span><span style="color:#961f8d">type</span><span style="color:#000000">=</span>&quot;DRL&quot;</p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco; color:rgb(66,57,246)">
<span class="Apple-style-span"><span class="Apple-style-span"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#961f8d">source</span><span style="color:#000000">=</span>&quot;</span>file:/Users/drools/drools-spring-test/src/Rules/drls/</span>EvaluateUnit<span class="Apple-style-span">.drl&quot;<span class="Apple-style-span">&quot;<span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></span></span></p>
<p style="margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; font:normal normal normal 11px/normal Monaco">
</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span>drools:grid-node<span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span><span style="color:#4239f6">&quot;node1&quot;</span><span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span><span style="color:#4b9191">drools:kbase</span><span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span>&quot;kbase1&quot;<span style="color:#000000">
</span><span style="color:#961f8d">node</span><span style="color:#000000">=</span>&quot;node1&quot;<span style="color:#009292">&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span>drools:resources<span style="color:#009292">&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span>drools:resource<span style="color:#000000">
</span><span style="color:#961f8d">ref</span><span style="color:#000000">=</span><span style="color:#4239f6">&quot;GroupUnit&quot;</span><span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span>drools:resource<span style="color:#000000">
</span><span style="color:#961f8d">ref</span><span style="color:#000000">=</span><span style="color:#4239f6">&quot;GradeUnit&quot;</span><span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span>drools:resource<span style="color:#000000">
</span><span style="color:#961f8d">ref</span><span style="color:#000000">=</span><span style="color:#4239f6">&quot;EvaluateUnit&quot;</span><span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span class="Apple-style-span" style="color:rgb(75,145,145)"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;/</span>drools:resources<span style="color:#009292">&gt;</span></span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4b9191"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;/</span>drools:kbase<span style="color:#009292">&gt;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#009292">&lt;</span><span style="color:#4b9191">drools:ksession</span><span style="color:#000000">
</span><span style="color:#961f8d">id</span><span style="color:#000000">=</span>&quot;ksession&quot;<span style="color:#000000">
</span><span style="color:#961f8d">type</span><span style="color:#000000">=</span>&quot;stateful&quot;<span style="color:#000000">
</span><span style="color:#961f8d">kbase</span><span style="color:#000000">=</span>&quot;kbase1&quot;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span></span><span style="color:#961f8d">node</span><span style="color:#000000">=</span>&quot;node1&quot;<span style="color:#000000">
</span><span style="color:#009292">/&gt;</span></p>
<div><span style="color:#009292"><br>
</span></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif">Then in my Controller call, I 'AutoWire' in the StatefulKnowledgeSession as follows :</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif"><br>
</span></font></div>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#777777">@Controller</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#777777">@RequestMapping<span style="color:#000000">( value =
</span><span style="color:#4239f6">&quot;foo&quot;</span><span style="color:#000000"> )</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span style="color:#951565">final</span>
<span style="color:#951565">class</span> FooController{</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; min-height:15.0px">
&nbsp;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#777777"><span style="color:#000000">&nbsp;&nbsp;
</span>@Autowired</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco">&nbsp;&nbsp; StatefulKnowledgeSession
<span style="color:#162bc4">ksession</span>;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; min-height:15.0px">
&nbsp; &nbsp;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco">&nbsp;&nbsp; <span style="color:#777777">
@RequestMapping</span>(&nbsp; method = RequestMethod.<span style="color:#162bc4">GET</span> )</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#777777"><span style="color:#000000">&nbsp;&nbsp;
</span>@ResponseBody</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco">&nbsp;&nbsp; <span style="color:#951565">
public</span> String evaluateUnit() {</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; min-height:15.0px">
<span class="Apple-tab-span" style="white-space:pre"></span>&nbsp; &nbsp;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>Unit unit =
<span style="color:#951565">new</span> Unit(<span style="color:#4239f6">&quot;030&quot;</span>,
<span style="color:#4239f6">&quot;502&quot;</span>, <span style="color:#4239f6">&quot;C&quot;</span>,
<span style="color:#4239f6">&quot;9484&quot;</span>, <span style="color:#4239f6">&quot;45&quot;</span>,
<span style="color:#951565">new</span> String[] {},</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span><span style="color:#951565">null</span>);</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; min-height:15.0px">
<span class="Apple-tab-span" style="white-space:pre"></span>&nbsp; &nbsp;</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
<span style="color:#951565">if</span> (<span style="color:#162bc4">ksession</span> !=
<span style="color:#951565">null</span>)<span class="Apple-tab-span" style="white-space:pre">
</span>{</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
<span style="color:#162bc4">ksession</span>.fireAllRules();</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
<span style="color:#162bc4">ksession</span>.insert(unit);</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
<span style="color:#162bc4">ksession</span>.fireAllRules();</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span class="Apple-style-span"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
</span><span style="color:#951565">return</span><span style="color:#000000"> </span>
&quot;&lt;UnitCategory&gt;&quot;<span style="color:#000000"> &#43; unit.getUnitCategory() &#43; </span>&quot;&lt;/</span>UnitCategory<span class="Apple-style-span">&gt;&quot;<span style="color:#000000">;</span></span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp; }</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
<span style="color:#951565">else</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco; color:#4239f6"><span style="color:#000000"><span class="Apple-tab-span" style="white-space:pre"></span>&nbsp;
</span><span style="color:#951565">return</span><span style="color:#000000"> </span>
&quot;&lt;message&gt; stateful session is null&lt;/message&gt;&quot;<span style="color:#000000">;</span></p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco">&nbsp;&nbsp; }</p>
<p style="margin:0.0px 0.0px 0.0px 0.0px; font:11.0px Monaco"><br>
</p>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif">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.</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif"><br>
</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif">Please let me know if I'm missing anything in my assessment here !</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif"><br>
</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif">Thanks in advance,</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif">Gurvinder</span></font></div>
<div><font class="Apple-style-span" color="#009292"><span class="Apple-style-span" style="font-size:14px; color:rgb(0,0,0); font-family:Calibri,sans-serif"><br>
</span></font></div>
<p></p>
</div>
<br>
<br>
<br>
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.
</body>
</html>