[rules-users] StatefulKnowledgeSession leaves threads running
Greg Barton
greg_barton at yahoo.com
Thu Jul 16 14:59:02 EDT 2009
I have seen similar behavior, though at the time I didn't have the opportunity to investigate the cause. (Sorry about not reporting it at the time.) Unlike the code below it was while calling session.fireUntilHalt(). (In a seperate thread.) After calling session.halt() from another thread the fireUntilHalt() would exit, but the VM would not exit due to a non-daemon thread persisting.
--- On Thu, 7/16/09, Rafael Ribeiro <rafaelri at gmail.com> wrote:
> From: Rafael Ribeiro <rafaelri at gmail.com>
> Subject: Re: [rules-users] StatefulKnowledgeSession leaves threads running
> To: "Rules Users List" <rules-users at lists.jboss.org>
> Date: Thursday, July 16, 2009, 12:10 PM
> Hi Edson!
>
> as I've already mentioned I've modified the
> sample so, if you get the StockTick sample and replace the
> Main class this will run fine.
> The sample shuts down fine but as I saw it sets the
> JFrame uses frame.setDefaultCloseOperation(
> WindowConstants.EXIT_ON_CLOSE ); which in turn makes the
> trick.
>
>
> Below the code of my modified main class:
>
> package org.drools.examples.broker;
>
>
> import org.drools.KnowledgeBase;
> import org.drools.KnowledgeBaseConfiguration;
> import org.drools.KnowledgeBaseFactory;
>
> import org.drools.builder.KnowledgeBuilder;
> import org.drools.builder.KnowledgeBuilderFactory;
> import org.drools.builder.ResourceType;
> import org.drools.conf.EventProcessingOption;
> import org.drools.examples.broker.model.Company;
>
> import org.drools.examples.broker.model.CompanyRegistry;
> import org.drools.examples.broker.model.StockTick;
> import org.drools.io.ResourceFactory;
> import org.drools.runtime.StatefulKnowledgeSession;
> import org.drools.runtime.rule.WorkingMemoryEntryPoint;
>
>
> public class Main {
> private static final String RULES_FILE =
> "/broker.drl";
> static StatefulKnowledgeSession session;
> static WorkingMemoryEntryPoint tickStream;
>
> /**
> * @param args
>
> */
> public static void main(String[] args) throws
> Exception {
> // set up and show main window
>
> CompanyRegistry companies = new
> CompanyRegistry();
>
> KnowledgeBuilder builder =
> KnowledgeBuilderFactory.newKnowledgeBuilder();
>
> try {
> builder.add(
> ResourceFactory.newInputStreamResource(
> Main.class.getResourceAsStream( RULES_FILE ) ),
>
> ResourceType.DRL);
> } catch ( Exception e ) {
> e.printStackTrace();
>
> }
> if( builder.hasErrors() ) {
>
> System.err.println(builder.getErrors());
> System.exit( 0 );
> }
>
> KnowledgeBaseConfiguration conf =
> KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
>
> conf.setOption( EventProcessingOption.STREAM
> );
> KnowledgeBase kbase =
> KnowledgeBaseFactory.newKnowledgeBase( conf );
> kbase.addKnowledgePackages(
> builder.getKnowledgePackages() );
>
>
> session =
> kbase.newStatefulKnowledgeSession();
>
> session.setGlobal( "services", new
> BrokerServices() {
> public void log(String message) {
>
> System.out.println(message);
>
> }
> });
>
> for( Company company :
> companies.getCompanies() ) {
> session.insert( company );
> }
> session.fireAllRules();
>
> tickStream =
> session.getWorkingMemoryEntryPoint( "StockTick
> stream" );
>
>
> for (int i=10;i>0;i--) {
> tickStream.insert(new
> StockTick("RHT", i*10,
> System.currentTimeMillis()));
> session.getAgenda().getAgendaGroup(
> "evaluation" ).setFocus();
>
> session.fireAllRules();
> }
> session.dispose();
> session.halt();
> System.out.println("Still
> running...");
> }
>
> }
>
>
> regards,
> Rafael Ribeiro
>
>
> 2009/7/16 Edson Tirelli <tirelli at post.com>
>
>
> Hi Rafael,
>
> Are you setting the MultithreadEvaluation option or is
> this using default options? Do you have an example code that
> shows this behavior?
>
> Thanks,
> Edson
>
>
>
> 2009/7/16 Rafael Ribeiro <rafaelri at gmail.com>
>
>
>
>
> Hi all,
>
>
>
> I've downloaded Drools fusion sample and started to
> make some changes to
>
> the code (first of all wipe out the UI so I can test it
> easier).
>
> I tried to get to a minimal set so I can run a console
> main class and see
>
> what happens but I am facing a strange behaviour.
>
> As soon as I start pushing events into the
> WorkingMemoryEntryPoint
>
> ("StockTick stream") a Thread - not daemonized
> since it blocks shutdown from
>
> ending - is spawned and this prevents my JVM from shutting
> down (obviously
>
> if I call System.exit(0) it will but I am avoiding this).
>
> I've tried both to halt and dispose the session that
> this entry point
>
> belongs but with no success. Does anyone know how could I
> get rid of this
>
> thread?
>
>
>
> best regards,
>
> --
>
>
>
>
> _______________________________________________
>
> rules-users mailing list
>
> rules-users at lists.jboss.org
>
> http://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> http://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list