Oh that looks like a cool way to standardize how all the threads inside drools are being created. <div>Do you have already identified where this new approach must be applied? The rule times are also implementing this approach? </div>

<div>Cheers<br><br><div class="gmail_quote">On Wed, Mar 14, 2012 at 5:27 PM, Mario Fusco <span dir="ltr">&lt;<a href="mailto:mario.fusco@gmail.com">mario.fusco@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi all,<br><br>following the suggestions of Mark on how to create a new Service I just pushed a new one named ExecutorProvider. The idea here is that we should never manually create and start Threads in the Drools code because this is inefficient and event worse is not portable in many enterprise environments. In this way it will be possible to provide different implementations of this Service that could work with J2EE, Spring or other similar managed environments.<br>


<br>The ExecutorProvider is defined as it follows:<br><br>public interface ExecutorProvider extends Service {<br>    Executor getExecutor();<br>    &lt;T&gt; CompletionService&lt;T&gt; getCompletionService();<br>}<br><br>


I am already using it to make the jitting compilation of my MvelConstraint an asynchronous process and also to replace the Threads used in the KnowledgeAgentImpl and ResourceChangeScannerImpl. For instance in the KnowledgeAgentImpl I replaced this code:<br>


<br>this.thread = new Thread( this.changeSetNotificationDetector );<br>this.thread.start();<br><br>with this one:<br><br>this.notificationDetectorExecutor =<br>                    ExecutorProviderFactory.getExecutorProvider().&lt;Boolean&gt;getCompletionService()<br>


                            .submit(this.changeSetNotificationDetector, true);<br><br>where the notificationDetectorExecutor is a Future so I can stop its execution with:<br><br>this.notificationDetectorExecutor.cancel(true);<br>


<br>instead of doing:<br><br>this.thread.interrupt();<br><br>Also note that, at the moment, the ExecutorService internally used in the ExecutorProviderImpl (the only ExecutorProvider implementation currently available) always uses daemon Threads, so the JVM won&#39;t be prevented to terminate if there are some of them still running.<span class="HOEnZb"><font color="#888888"><br>


<br>Mario<br>
</font></span><br>_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br> - MyJourney @ <a href="http://salaboy.wordpress.com" target="_blank">http://salaboy.wordpress.com</a><div> - Co-Founder @ <a href="http://www.jugargentina.org" target="_blank">http://www.jugargentina.org</a><br>

 - Co-Founder @ <a href="http://www.jbug.com.ar" target="_blank">http://www.jbug.com.ar</a><br> <br> - Salatino &quot;Salaboy&quot; Mauricio -</div><br>
</div>