[
http://jira.jboss.com/jira/browse/JBRULES-1554?page=comments#action_12411594 ]
Edson Tirelli commented on JBRULES-1554:
----------------------------------------
Hi Jan,
Thanks for reporting and providing test case. The problem is that your example is sharing
the Package objects among multiple threads. Package was never designed to be shared, since
it contains objects whose attributes change when added to a rulebase.
In your specific example, the "or" in the rule is forcing the RulebaseBuilder to
clone the $str declaration for each logical branch and recalculating its offset. That will
obviously cause problems when the package object is shared among multiple rulebases.
Changing your test to share the already compiled rulebase (the way it was always designed
to be) or share nothing between threads, makes it work.
So, the question is: is there a valid use case for sharing the packages instead of the
compiled rulebase?
One option is to clone the packages for each thread you want to use. A simple way of doing
that is cloning by in-memory serialization (in case you don't store the packages
already serialized):
protected static Object serializeIn(final byte[] bytes) throws IOException,
ClassNotFoundException {
final ObjectInput in = new ObjectInputStream( new ByteArrayInputStream( bytes )
);
final Object obj = in.readObject();
in.close();
return obj;
}
protected static byte[] serializeOut(final Object obj) throws IOException {
// Serialize to a byte array
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final ObjectOutput out = new ObjectOutputStream( bos );
out.writeObject( obj );
out.close();
// Get the bytes of the serialized object
final byte[] bytes = bos.toByteArray();
return bytes;
}
======
Package pkg = precompilePackages();
byte[] serializedPkg = serializeOut( pkg );
int threadCount=30;
int iterations = 300;
TestThread[] threads= new TestThread[threadCount];
for(int i =0;i<threadCount;i++)
{
threads[i]= new TestThread();
threads[i].setPkg( (Package) serializeIn( serializedPkg ));
=======
What do you think?
Edson
"not in" used with "or" is not thread safe
------------------------------------------
Key: JBRULES-1554
URL:
http://jira.jboss.com/jira/browse/JBRULES-1554
Project: JBoss Drools
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Reteoo
Affects Versions: 4.0.5
Reporter: Jan Boboli
Assigned To: Edson Tirelli
Fix For: 5.0.0-M1, 4.0.7
Attachments: ll.zip, project2.zip
"not in" used with "or" is not thread safe.
following construct causes ClassCastExeption when executed in parallel by different
threads :
when:
$validateOrderIn : ValidateOrderIn(
)
Sim(
$sim : sim
)
(
__sims(
sim == $sim,
$status : status not in ( "n", "o", "p")
)
)
or
(
__sims(
sim == $sim,
$status : status not in ("r", "l", "m" )
)
)
then ...
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira