Re: ConcurrentModificationException ...

From: Cris Daniluk (cris.danilu..mail.com)
Date: Mon Apr 24 2006 - 11:12:35 EDT

  • Next message: Marcin Skladaniec: "Re: toMany relationship not fetched"

    On 4/24/06, Arnaud GARCIA <arnaud.garci..im.hcuge.ch> wrote:
    > Hello,
    > I have a problem with multithreaded access with cayenne ...
    > My model is a simple one to many relationship (an Order can have many
    > series)
    >
    > In my main thread I add new series to an Order :
    > order.addToSeries(aSerie);
    >
    > But in another thread I am doing an Iteration over the series which
    > launch an exception:
    > List series = order.getSeries();
    > for (Iterator iter = series.iterator(); iter.hasNext();) {
    > ...
    > }

    Cayenne is returning its internal reference to the collection. This is
    easy to avoid by just wrapping the collection:

    List series = new ArrayList(order.getSeries());

    This is a good general habit to be in anyway... in single-theaded
    apps, you'll still get the CME if you attempt to modify the collection
    (through remove, etc)

    Cris



    This archive was generated by hypermail 2.0.0 : Mon Apr 24 2006 - 11:12:58 EDT