Thank you very much, Greeta!
I'm just doing that :)) I'm moving out all instance stuff out of the class
declaration into local methods and transfer them into methods through
arguments.
Thanks to all you guys for your kind advices, I'm on the road now. My old
painfull problem is resolved! I started programming in Struts about 2 years
ago but didn't pay my attention on design guidelines when coding Action
classes. Too shame to me :((
----- Original Message -----
From: "Geeta Ramani" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 4:22 PM
Subject: Re: ConcurrentModificationException
|
| Sergei:
|
| But you're getting there..:) Take the declaration of ArrayList *out* of:
|
| >public class MyAction extends Action {
| > protected ArrayList list = new ArrayList(); --->Take this out: BAD!!
|
| and move it inside the methods to make them local..:
|
| >public ActionForward execute(...) ... {
| > ArrayList list = new ArrayList(); -->GOOD!!
| > myMethod(list); --->GOOD!!
|
| and:
|
| > protected void myMethod(ArrayList list) { -->GOOD!!
| > ArrayList list = new ArrayList(); -->Take this out: BAD!!
|
| Regards,
| Geeta
|
| Niall Pemberton wrote:
|
| > This is no good either. Action classes are not thread safe.
| >
| > Why not read the user manual. Theres a section "4.4.1 Action Class
Design
| > Guidelines"
| >
| >
http://jakarta.apache.org/struts/userGuide/building_controller.html#action_classes
| >
| > ----- Original Message -----
| > From: "Sergei P. Volin" <[EMAIL PROTECTED]>
| > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
| > Sent: Thursday, March 04, 2004 9:32 AM
| > Subject: Re: ConcurrentModificationException
| >
| > >
| > > Greetings,
| > >
| > > That is the question! Today morning I've found the reason of my
troubles.
| > It
| > > was my negligence in how I assigned a value to the iterated list that
I
| > > placed in the object which I then stored in a session for JSP's
iterator.
| > I
| > > declared the list in my action as a global variable, assigned a value
to
| > it
| > > in the protected void method which is called by the action execute
method
| > > like this:
| > >
| > > public class MyAction extends Action {
| > > protected ArrayList list = new ArrayList();
| > > ...
| > > public ActionForward execute(...) ... {
| > > list = new ArrayList();
| > > myMethod(...);
| > > obj.setList(list)
| > > session.setAttribute("buinessObj", obj);
| > > ...
| > > return mapping.findForward(forward);
| > > }
| > > protected void myMethod(...) {
| > > ...
| > > while (rs.next()) {
| > > ...
| > > list.add(el);
| > > ...
| > > }
| > > }
| > > }
| > >
| > > Now this piece of code looks like:
| > >
| > > public class MyAction extends Action {
| > > protected ArrayList list = new ArrayList();
| > > ...
| > > public ActionForward execute(...) ... {
| > > list = new ArrayList();
| > > myMethod(...);
| > > obj.setList(list)
| > > session.setAttribute("buinessObj", obj);
| > > ...
| > > return mapping.findForward(forward);
| > > }
| > > protected void myMethod(...) {
| > > ArrayList list = new ArrayList(); // new
| > > ...
| > > while (rs.next()) {
| > > ...
| > > list.add(el);
| > > ...
| > > }
| > > this.list =list; // new
| > > }
| > > }
| > >
| > > It looks that with this code I rid off all my troubles now - no
| > > ConcurrentModificationException, no doubling of list size. I made a
dozen
| > of
| > > tests - no exceptions and the results were correct.
| > >
| > > Mr. Craig R. McClanahan! Am I right now with my code? Please, reply.
| > > Thanks a lot,
| > >
| > > Sergei Volin.
| > >
| > >
| > > ----- Original Message -----
| > > From: "Craig R. McClanahan" <[EMAIL PROTECTED]>
| > > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>;
"Sergei
| > P.
| > > Volin" <[EMAIL PROTECTED]>
| > > Cc: "Struts Users Mailing List" <[EMAIL PROTECTED]>
| > > Sent: Thursday, March 04, 2004 1:08 AM
| > > Subject: Re: ConcurrentModificationException
| > >
| > >
| > > |
| > > | Quoting "Sergei P. Volin" <[EMAIL PROTECTED]>:
| > > |
| > > | >
| > > | > I know this and I do not add/remove elements to/from list at all.
Just
| > > as I
| > > | > said - only reading elements from list.
| > > | > Are jsps (Tomcat) thread safe? I'm really worry about that.
| > > | >
| > > |
| > > | Using instance variables to store request-specific state
information, in
| > a
| > > JSP
| > > | or servlet (or in a Struts Action class), is *not* thread safe,
because
| > > there
| > > | is only one instance of the corresponding class, shared by
simultaneous
| > > | requests. Using local variables, though, should be fine.
| > > |
| > > | Craig McClanahan
| > > |
| > > |
| > >
| ---------------------------------------------------------------------
| > > | 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]
|
|
| ---------------------------------------------------------------------
| 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]