You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Richard Mixon (qwest)" <rn...@custco.biz> on 2003/12/31 16:36:26 UTC
ConcurrentModificationException on ActionErrors
I have a Struts action that is trying to show all of the errors that might occur from either or both of two subordinate methods. The
code looks like:
...
ActionErrors errors = new ActionErrors();
ActionErrors errors1 = null;
ActionErrors errors2 = null;
Obj1 obj1 = new Obj1();
Obj2 obj2 = new Obj2();
obj1.method1();
errors1 = obj1.getErrors();
if (!errors1.isEmpty()) {
errors.add(errors1);
}
obj2.method2();
errors2 = obj2.getErrors();
if (!errors2.isEmpty()) {
errors.add(errors1);
}
...
Problem is I get the ConcurrentModificationException when I try and do either of the "errors.add" methods above. Methods
method1/method2 are pretty vanilla, just doing some database work and accumulating any errors in an associated ActionErrors.
I've searched the archives but only found one or two references to ConcurrentModificationException and they did not involve
ActionErrors. Any ideas or help is appreciated.
- Richard
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: ConcurrentModificationException on ActionErrors
Posted by Kris Schneider <kr...@dotech.com>.
Although it's possible to generate that exception from within the same thread,
it's usually triggered by multiple threads accessing the same collection. In
general, if you grab an iterator, then modify the underlying collection, and
then call iter.next(), you'll see that exception. Having multiple iterators
shouldn't be an issue - you don't explicitly close an iterator like a database
connection. It will be GC-ed just like any other object. The problem really
boils down to modifying the backing collection while iteration is in progress.
By "in progress", I mean doing something like calling iter.next(), not that
there's just an iterator instance lying around.
Quoting "Richard Mixon (qwest)" <rn...@custco.biz>:
> Kris,
>
> Thanks - I do not think I have multiple threads involved, but certaily
> multiple Iterators may be hanging around that are not GC'd
> yet.
>
> And yes that was a typo. Because the real code is so huge, I created a simple
> example to paste in and obviously did not compile it
> :)
>
> - Richard
>
> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Wednesday, December 31, 2003 9:01 AM
> To: Struts Users Mailing List
> Subject: Re: ConcurrentModificationException on ActionErrors
>
>
> It almost sounds like your code isn't handling errors1 and/or errors2 in a
> thread-safe manner. ConcurrentModificationException will be thrown if one
> thread
> is in the proces of iterating over a collection and another thread modifies
> that
> collection. ActionMessages.add(ActionMessages) will iterate over both the
> arg's
> properties and the messages for each property, so there's certainly the
> potential for the error you're seeing. Can you provide some more detail on
> how
> your code is organized?
>
> BTW, not sure if it's a c/p error, but you've got:
>
> if (!errors2.isEmpty()) {
> errors.add(errors1); // shouldn't that be errors2?
> }
>
> Quoting "Richard Mixon (qwest)" <rn...@custco.biz>:
>
> > I have a Struts action that is trying to show all of the errors that
> might
> > occur from either or both of two subordinate methods. The
> > code looks like:
> >
> > ...
> > ActionErrors errors = new ActionErrors();
> > ActionErrors errors1 = null;
> > ActionErrors errors2 = null;
> >
> > Obj1 obj1 = new Obj1();
> > Obj2 obj2 = new Obj2();
> >
> > obj1.method1();
> > errors1 = obj1.getErrors();
> > if (!errors1.isEmpty()) {
> > errors.add(errors1);
> > }
> >
> > obj2.method2();
> > errors2 = obj2.getErrors();
> > if (!errors2.isEmpty()) {
> > errors.add(errors1);
> > }
> > ...
> >
> > Problem is I get the ConcurrentModificationException when I try and do
> either
> > of the "errors.add" methods above. Methods
> > method1/method2 are pretty vanilla, just doing some database work and
> > accumulating any errors in an associated ActionErrors.
> >
> > I've searched the archives but only found one or two references to
> > ConcurrentModificationException and they did not involve
> > ActionErrors. Any ideas or help is appreciated.
> >
> > - Richard
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech <http://www.dotech.com/>
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: ConcurrentModificationException on ActionErrors
Posted by "Richard Mixon (qwest)" <rn...@custco.biz>.
Kris,
Thanks - I do not think I have multiple threads involved, but certaily multiple Iterators may be hanging around that are not GC'd
yet.
And yes that was a typo. Because the real code is so huge, I created a simple example to paste in and obviously did not compile it
:)
- Richard
-----Original Message-----
From: Kris Schneider [mailto:kris@dotech.com]
Sent: Wednesday, December 31, 2003 9:01 AM
To: Struts Users Mailing List
Subject: Re: ConcurrentModificationException on ActionErrors
It almost sounds like your code isn't handling errors1 and/or errors2 in a
thread-safe manner. ConcurrentModificationException will be thrown if one thread
is in the proces of iterating over a collection and another thread modifies that
collection. ActionMessages.add(ActionMessages) will iterate over both the arg's
properties and the messages for each property, so there's certainly the
potential for the error you're seeing. Can you provide some more detail on how
your code is organized?
BTW, not sure if it's a c/p error, but you've got:
if (!errors2.isEmpty()) {
errors.add(errors1); // shouldn't that be errors2?
}
Quoting "Richard Mixon (qwest)" <rn...@custco.biz>:
> I have a Struts action that is trying to show all of the errors that might
> occur from either or both of two subordinate methods. The
> code looks like:
>
> ...
> ActionErrors errors = new ActionErrors();
> ActionErrors errors1 = null;
> ActionErrors errors2 = null;
>
> Obj1 obj1 = new Obj1();
> Obj2 obj2 = new Obj2();
>
> obj1.method1();
> errors1 = obj1.getErrors();
> if (!errors1.isEmpty()) {
> errors.add(errors1);
> }
>
> obj2.method2();
> errors2 = obj2.getErrors();
> if (!errors2.isEmpty()) {
> errors.add(errors1);
> }
> ...
>
> Problem is I get the ConcurrentModificationException when I try and do either
> of the "errors.add" methods above. Methods
> method1/method2 are pretty vanilla, just doing some database work and
> accumulating any errors in an associated ActionErrors.
>
> I've searched the archives but only found one or two references to
> ConcurrentModificationException and they did not involve
> ActionErrors. Any ideas or help is appreciated.
>
> - Richard
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: ConcurrentModificationException on ActionErrors
Posted by Kris Schneider <kr...@dotech.com>.
It almost sounds like your code isn't handling errors1 and/or errors2 in a
thread-safe manner. ConcurrentModificationException will be thrown if one thread
is in the proces of iterating over a collection and another thread modifies that
collection. ActionMessages.add(ActionMessages) will iterate over both the arg's
properties and the messages for each property, so there's certainly the
potential for the error you're seeing. Can you provide some more detail on how
your code is organized?
BTW, not sure if it's a c/p error, but you've got:
if (!errors2.isEmpty()) {
errors.add(errors1); // shouldn't that be errors2?
}
Quoting "Richard Mixon (qwest)" <rn...@custco.biz>:
> I have a Struts action that is trying to show all of the errors that might
> occur from either or both of two subordinate methods. The
> code looks like:
>
> ...
> ActionErrors errors = new ActionErrors();
> ActionErrors errors1 = null;
> ActionErrors errors2 = null;
>
> Obj1 obj1 = new Obj1();
> Obj2 obj2 = new Obj2();
>
> obj1.method1();
> errors1 = obj1.getErrors();
> if (!errors1.isEmpty()) {
> errors.add(errors1);
> }
>
> obj2.method2();
> errors2 = obj2.getErrors();
> if (!errors2.isEmpty()) {
> errors.add(errors1);
> }
> ...
>
> Problem is I get the ConcurrentModificationException when I try and do either
> of the "errors.add" methods above. Methods
> method1/method2 are pretty vanilla, just doing some database work and
> accumulating any errors in an associated ActionErrors.
>
> I've searched the archives but only found one or two references to
> ConcurrentModificationException and they did not involve
> ActionErrors. Any ideas or help is appreciated.
>
> - Richard
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org