[rules-dev] Help with DefaultAgenda.Java

Mark Proctor mproctor at codehaus.org
Sun Mar 10 09:24:00 EDT 2013


Malory,

I'm replying here, rather than to your private email. We are an open source community, by asking these questions publicly it ensures all can participate and learn, and the conversations are archived for searching.

Your line numbers seem off. I'm looking at line 39 in DefaultConsequenceExceptionHandler:
https://github.com/droolsjbpm/drools/blob/5.4.x/drools-core/src/main/java/org/drools/base/DefaultConsequenceExceptionHandler.java

Line 39 is the last argument of the method declaration. Also the only thing that could cause null pointer while handleException is if you were to pass a null Activation.

I think you are trying to do this too high up, where there is all sorts of thread safety issues you are exposing by putting Runnable around fireNextItem. There is shared states that those threads will access, which will cause problems.

Better to do it when the consequence is invoked directly:
activation.getConsequence().evaluate( this.knowledgeHelper, this.workingMemory );

Mark

On 10 Mar 2013, at 08:05, gmalathi.in at gmail.com wrote:

> Hi Mark,
> 
> I have tried to change the source code of DefaultAgenda.Java by adding the code below: 
> 
>     //drools orginial sequential code
>      /*  
>        while ( continueFiring( fireLimit ) && fireNextItem( agendaFilter ) ) {
>            fireCount++;
>            fireLimit = updateFireLimit( fireLimit );
>            this.workingMemory.executeQueuedActions();
>        }
>        */
> 
> 
>        //code with concurrency
> 
>        InternalAgendaGroup myGroup = (InternalAgendaGroup) getNextFocus(); 
>        fireCount = myGroup.size();
> 
>        for(int i =0; i< fireCount; ++i)
>        {
>        	
>        	new Thread(new Runnable(){
>        		public void run()
>        		{
>        			fireNextItem( agendaFilter );
>        			
>        		}
>        	}).start();       
>        	
>        }
> 
> 
> I am getting an Errorjava.lang.NullPointerException because my code flow is going to consequenceExceptionHandler ! = null exception.
> 
> else if ( this.consequenceExceptionHandler != null ) {
> 
>                    this.consequenceExceptionHandler.handleException( activation, this.workingMemory.getKnowledgeRuntime(),
>                                                                      e );
> 
> 
> Could you kindly help me with this?
> 
> I am pasting the exception below and I am using Drools 5.4 Final version.
> 
> In DA: [Activation rule=Rule 1, act#=0, salience=0, tuple=[fact 0:0:1773684356:1306428912:0:DEFAULT:org.drools.reteoo.InitialFactImpl at 4dde85f0]
> ]
> Exception in thread "Thread-1" Exception in thread "Thread-0" Exception executing consequence for rule "Rule 1" in defaultpkg: java.lang.NullPointerException
> In DA WM: org.drools.impl.StatefulKnowledgeSessionImpl at 542487b1
> In DA Errorjava.lang.NullPointerException
> In DA: [Activation rule=Rule 2, act#=1, salience=0, tuple=[fact 0:0:1773684356:1306428912:0:DEFAULT:org.drools.reteoo.InitialFactImpl at 4dde85f0]
> ]
> In DA WM: org.drools.impl.StatefulKnowledgeSessionImpl at 542487b1
> In DA Errorjava.lang.NullPointerException
> 	at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
> 	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1208)
> 	at org.drools.common.DefaultAgenda$1.run(DefaultAgenda.java:1471)
> 	at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.NullPointerException
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1272)
> 	... 3 more
> Exception executing consequence for rule "Rule 2" in defaultpkg: java.lang.NullPointerException
> 	at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287)
> 	at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1208)
> 	at org.drools.common.DefaultAgenda$1.run(DefaultAgenda.java:1471)
> 	at java.lang.Thread.run(Unknown Source)
> Caused by: java.lang.NullPointerException
> 	at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1272)
> 	... 3 more
> 
> 
> Thanks a lot for the help.
> 
> Regards,
> Malory




More information about the rules-dev mailing list