Cloning isn't actually that expensive at all... for modification, clone the
data, modify it, then set the reference back to the original member
variable, problem solved.  Look at the source for FastHashMap or
FastArrayList from commons-collections.

-Jacob

-----Original Message-----
From: Yansheng Lin [mailto:[EMAIL PROTECTED]
Sent: Monday, June 23, 2003 11:26 AM
To: 'Struts Users Mailing List'
Subject: RE: java.util.ConcurrentModificationException at
org.apache.struts.action.ActionMessages.add(ActionMessages.java:185)



I saw this error a lot before if I didn't use an iterator on an Arraylist.
So
another solution(I use most of the time) is to declare an iterator for that
ArrayList and modify the iterator instead.  synchronize() would prevent the
exception be thrown, but i wonder how many calls there are behind the
synchronize() method?  To me, it's a bit of performance overhead.  I am not
sure:).

Hey, I am not sure a lot of things that's going on inside of Struts
anyways:). 


-----Original Message-----
From: Fedor Smirnoff [mailto:[EMAIL PROTECTED] 
Sent: June 22, 2003 1:49 PM
To: Struts Users Mailing List
Subject: RE: java.util.ConcurrentModificationException at
org.apache.struts.action.ActionMessages.add(ActionMessages.java:185)


Thats a good solution, I will use that, thanks. I am a
bit confused as to why this is happening because the
array is being populated in the form bean, and than
the jsp page that uses this bean displays the array
list in as html:select. I guess the question would be,
is it being displayed/iterated AFTER the bean finished
creating the list.

Thanks,
Fedor

--- Johan Kumps <[EMAIL PROTECTED]> wrote:
> I think there is a thread on your backend writing to
> the ArrayList at the
> same time your action class is reading the sam
> ArrayList instance.
> 
> I also had this problem and I fixed it by
> synchronizing the Arraylist during
> the write(add) process.
> 
> synchronized (this.myArrayList) {
>       this.myArrayList.add(someElement);
> }
> 
> Hope this helps.
> 
> Kind regards,
> 
> -----Oorspronkelijk bericht-----
> Van: Fedor Smirnoff [mailto:[EMAIL PROTECTED]
> Verzonden: zondag 22 juni 2003 0:06
> Aan: Struts Users Mailing List
> Onderwerp: Re:
> java.util.ConcurrentModificationException at
>
org.apache.struts.action.ActionMessages.add(ActionMessages.java:185)
> 
> 
> I am not using 2 threads, I was just saying than in
> case of two threds being used, this Exception will
> be
> thrown.  I can find whats the problem in my casei
> got
> this:
> 
>      <html:select property="colorSelected">
>        <html:options property="colorOptions"
>  name="orderEntryForm"/>
>      </html:select>
> 
>  where colorSelected is a String with getter and
>  setter in the orderEntry form bean, and
> colorOptions
> is being returned by a getter in the same bean as an
>  ArrayList.
>  Something like this:
> 
>    public ArrayList getColorOptions() {
>        colorOptions.add("red");
>        colorOptions.add("green");
>        return colorOptions;
> 
> Exception is being thrown when I am tryin to run it,
> however if I return a String[] instead of ArrayList,
> evetyhing works great.
> 
> Any ideas?
> 
> Thaks
> Fedor
> --- Sandeep Takhar <[EMAIL PROTECTED]> wrote:
> > You don't need two threads.
> >
> > If you are using an iterator and are removing from
> > the
> > collection you are iterating over - you will get
> > this
> > error.
> >
> > If you are using EJB CMP then you need to know how
> > relationships work because it is easy to run into
> > this.
> >
> > sandeep
> > --- Fedor Smirnoff <[EMAIL PROTECTED]>
> wrote:
> > > Hi I asked similar question and yet did not get
> an
> > > answer, I dont know why its happening in my
> case,
> > > however, I know that
> > ConcurrentModificationException
> > > is thrown when a thread is trying to modify a
> > > collection while another thread is still
> iterating
> > > it.
> > > Dont know if it helps you or not sorry.
> > >
> > > Sincerely,
> > > Fedor
> > >
> > > --- Michael Ruppin <[EMAIL PROTECTED]> wrote:
> > > > I'm getting the following, using 1.1-rc1
> > > > ActionMessages.add(ActionMessages messages):
> > > >
> > > > [6/20/03 11:15:23:344 CDT]  2d4fa5a WebGroup
> >
> > > E
> > > > SRVE0026E: [Servlet
> Error]-[AxisPortalServlet]:
> > > > java.util.ConcurrentModificationException
> > > >         at
> > > >
> > >
> >
>
java.util.AbstractList$Itr.checkForComodification(AbstractList.java(Inlined
> > > > Compiled Code))
> > > >         at
> > > >
> > >
> >
>
java.util.AbstractList$Itr.next(AbstractList.java(Compiled
> > > > Code))
> > > >         at
> > > >
> > >
> >
>
org.apache.struts.action.ActionMessages.add(ActionMessages.java:185)
> > > >
> > > > __________________________________
> > > > Do you Yahoo!?
> > > > SBC Yahoo! DSL - Now only $29.95 per month!
> > > > http://sbc.yahoo.com
> > > >
> > > >
> > >
> >
>
---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > > [EMAIL PROTECTED]
> > > > For additional commands, e-mail:
> > > > [EMAIL PROTECTED]
> > > >
> > >
> > >
> > > __________________________________
> > > Do you Yahoo!?
> > > SBC Yahoo! DSL - Now only $29.95 per month!
> > > http://sbc.yahoo.com
> > >
> > >
> >
>
---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > [EMAIL PROTECTED]
> > > For additional commands, e-mail:
> > > [EMAIL PROTECTED]
> > >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> 
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system
> (http://www.grisoft.com).
> Version: 6.0.488 / Virus Database: 287 - Release
> Date: 5/06/2003
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to