I think Alan Moore wrote: [Charset iso-8859-1 unsupported, filtering to ASCII...] > I received the following exception while calling Rete.listDefinstances(): > > stackTrace: java.util.ConcurrentModificationException > at java.util.HashMap$HashIterator.nextEntry(HashMap.java:750) > at java.util.HashMap$KeyIterator.next(HashMap.java:786) > at java.util.AbstractCollection.toArray(AbstractCollection.java:170) > at java.util.ArrayList.<init>(ArrayList.java:132) > at jess.DefinstanceList.listDefinstances(DefinstanceList.java:52) > at jess.Rete.listDefinstances(Rete.java:499) > > There is a strong possibility that (definstance) was being called by a rule > running on another thread at the time. > > This brings up a couple of questions: > > 1) Is this expected behavior?
This is a bug. As you can see Jess makes a copy of the internal datastructure so that once the iterator is created, you won't see errors like this, but the copy operation should be protected and it's not. This isn't a safety issue for Jess's internals, but just an inconvenience for you. A sensible patch would be to synchrionize jess.DefinstanceList.listDefinstances(). > 2) In general, does jess make any guarantees w.r.t. concurrent modifications > for public API's that return collections/iterators? No, actually, it doesn't. I'll revisit this issue and make sure that this kind of problem can't occur. > 3) Is there a difference between calling (definstance) or > Rete.definstance(...)? No. > 4) Does jess maintain a lock object (or some other mechanism) I can use to > make sure my access to the API is safe? Jess is written to maintain the integrity of its own data structures, but the listXXX APIs weren't given the same consideration. In general changes to Jess's state can invalidate the iterators these methods return. I think it's probably prudent to trade efficiency for safety here, and lock-and-copy before returning iterators. --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 PO Box 969, MS 9012 [EMAIL PROTECTED] Livermore, CA 94550 http://herzberg.ca.sandia.gov -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------