java - Threads blocking during ReteMemory initialization -


in application, threads blocking during initialization of drools session

java.lang.thread.state: blocked @ org.drools.reteoo.common.reteworkingmemory.initinitialfact(reteworkingmemory.java:108)     - waiting lock <5385ba43> (a java.lang.integer) owned "thead-23" t@42     @ org.drools.reteoo.common.reteworkingmemory.fireallrules(reteworkingmemory.java:129)     @ org.drools.core.impl.statefulknowledgesessionimpl.fireallrules(statefulknowledgesessionimpl.java:1260)     @ org.drools.impl.adapters.statefulknowledgesessionadapter.fireallrules(statefulknowledgesessionadapter.java:72)   java.lang.thread.state: blocked @ org.drools.reteoo.common.reteworkingmemory.initinitialfact(reteworkingmemory.java:108)     - waiting lock <5385ba43> (a java.lang.integer) owned "thead-01" t@42     @ org.drools.reteoo.common.reteworkingmemory.fireallrules(reteworkingmemory.java:129)     @ org.drools.core.impl.statefulknowledgesessionimpl.fireallrules(statefulknowledgesessionimpl.java:1260)     @ org.drools.impl.adapters.statefulknowledgesessionadapter.fireallrules(statefulknowledgesessionadapter.java:72) 

the easiest way replicate issue creating drools file following condition:-

rule "slowwhencondition"    when       eval(myslowcondition(fact))    end 

create statefulsession , fire rules multiple threads. observe threads in blocking state using jvisualvm or stack trace.

upon investigating further figured following code invoked during initialization of reteworkingmemory causing problem

private final integer synclock = 42; public void initinitialfact() {     if ( initialfacthandle == null ) {         synchronized ( synclock ) {             if ( initialfacthandle == null ) {                 // double check, inside of sync point incase other thread beat it.                 initinitialfact(kbase, null);             }         }     } } 

an integer constant used locking causes threads having unrelated rules block on each other. obvious fix changing synclock integer constant object synclock = new object(). there reason why should not changed.

i working on drools 6.3 final , using java 8 on centos. each thread in application creates own stateful session.

the issue has been resolved suggested fix , part of drools 6.4. more information can found @ following location https://issues.jboss.org/browse/drools-1046


Comments