Re: [rules-users] StatefulKnowledgeSession leaves threads running
Rafael Ribeiro wrote: 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? Drools is starting up threads in a number of places now - using new Thread(). I think the plan is to change this to an interface call that allows pluggable implementations. So that the user can decide how threads are executed and stopped. Mark best regards, ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
The problem here is a different one. The engine is calling shutdown() on a thread pool and even without any task being executed, the thread is blocked in an internal JDK queue waiting for the timeout. I replaced the call by shutdownNow(), forcing the jdk to signal an interrupt to the thread and this seemed to work. I am investigating side effects of this procedure right now. []s Edson 2009/7/16 Mark Proctor mproc...@codehaus.org Rafael Ribeiro wrote: 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? Drools is starting up threads in a number of places now - using new Thread(). I think the plan is to change this to an interface call that allows pluggable implementations. So that the user can decide how threads are executed and stopped. Mark best regards, ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss by Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
Edson: Is it a code change inside Drools or is there any other shutdown method that I may call ? Mark: I completely agree with this future change, it makes much sense in an AppServer environment where we shouldn't be handling thread creation and disposal by ourselves. regards, Rafael 2009/7/17 Edson Tirelli tire...@post.com The problem here is a different one. The engine is calling shutdown() on a thread pool and even without any task being executed, the thread is blocked in an internal JDK queue waiting for the timeout. I replaced the call by shutdownNow(), forcing the jdk to signal an interrupt to the thread and this seemed to work. I am investigating side effects of this procedure right now. []s Edson 2009/7/16 Mark Proctor mproc...@codehaus.org Rafael Ribeiro wrote: 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? Drools is starting up threads in a number of places now - using new Thread(). I think the plan is to change this to an interface call that allows pluggable implementations. So that the user can decide how threads are executed and stopped. Mark best regards, ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss by Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
Rafael, It is the JDK class: Class ScheduledThreadPoolExecutor Check the API for methods shutdown() and shutdownNow(). I am also looking at the JDK source code. It seems safe in our case to change the call to shutdownNow() instead of the previous call to shutdown(). The shutdown is called on session dispose() only and as so it is an irreversible operation anyway. I am just double checking, but I think there is no choice. Brian Goetz's Java Concurrency in Practice also states that the jdk blocking operations may or may not be canceled gracefully (case-by-case) on chapter 7. Give me another hour to make sure everything is ok and I will commit a fix. https://jira.jboss.org/jira/browse/JBRULES-2211 []s Edson 2009/7/17 Rafael Ribeiro rafae...@gmail.com Edson: Is it a code change inside Drools or is there any other shutdown method that I may call ? Mark: I completely agree with this future change, it makes much sense in an AppServer environment where we shouldn't be handling thread creation and disposal by ourselves. regards, Rafael 2009/7/17 Edson Tirelli tire...@post.com The problem here is a different one. The engine is calling shutdown() on a thread pool and even without any task being executed, the thread is blocked in an internal JDK queue waiting for the timeout. I replaced the call by shutdownNow(), forcing the jdk to signal an interrupt to the thread and this seemed to work. I am investigating side effects of this procedure right now. []s Edson 2009/7/16 Mark Proctor mproc...@codehaus.org Rafael Ribeiro wrote: 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? Drools is starting up threads in a number of places now - using new Thread(). I think the plan is to change this to an interface call that allows pluggable implementations. So that the user can decide how threads are executed and stopped. Mark best regards, ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss by Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users -- Edson Tirelli JBoss Drools Core Development JBoss by Red Hat @ www.jboss.com ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] StatefulKnowledgeSession leaves threads running
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, -- View this message in context: http://www.nabble.com/StatefulKnowledgeSession-leaves-threads-running-tp24503855p24503855.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org http://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
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 rafae...@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@lists.jboss.org http://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
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;i0;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 tire...@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 rafae...@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@lists.jboss.org http://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org http://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] StatefulKnowledgeSession leaves threads running
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 rafae...@gmail.com wrote: From: Rafael Ribeiro rafae...@gmail.com Subject: Re: [rules-users] StatefulKnowledgeSession leaves threads running To: Rules Users List rules-users@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;i0;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 tire...@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 rafae...@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@lists.jboss.org http