StatefulKnowledgeSession leaves threads running
-----------------------------------------------
Key: JBRULES-2211
URL:
https://issues.jboss.org/browse/JBRULES-2211
Project: Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: drools-core
Affects Versions: 5.0.0.FINAL, 5.0.1.FINAL
Reporter: Edson Tirelli
Assignee: Edson Tirelli
Fix For: 5.2.0.CR1
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?
==================
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
--
This message is automatically generated by JIRA.
For more information on JIRA, see: