instance variables in struts action classes

Discussion in 'Java' started by javadude, Feb 22, 2005.

  1. javadude

    javadude Guest

    Just a sanity check question here: My understanding is that Struts does
    not, by default, create a new Action class instance per request? That
    said, if one kept an instance variable in an action class, you'd better
    make sure that it does not reflect any client state, correct?

    Thanks in advance
     
    javadude, Feb 22, 2005
    #1
    1. Advertising

  2. javadude

    Oscar kind Guest

    javadude <> wrote:
    > Just a sanity check question here: My understanding is that Struts does
    > not, by default, create a new Action class instance per request? That
    > said, if one kept an instance variable in an action class, you'd better
    > make sure that it does not reflect any client state, correct?


    Yes. Even better, is not to use any instance variables at all: the code
    in a class instance may be executed in multiple threads concurrently. The
    use of any non-static, non-final instance variable introduces more bugs
    (IMNSHO) than it's use can ever justify.

    Form classes are a different story though: they are guaranteed to be
    recreated for each request or session, depending on your configuration.
    Any state information should thus be kept there.


    --
    Oscar Kind http://home.hccnet.nl/okind/
    Software Developer for contact information, see website

    PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
     
    Oscar kind, Feb 22, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    951
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,302
    rjweytens
    Jun 25, 2004
  3. runescience

    Struts mapping action to action???

    runescience, Feb 6, 2006, in forum: Java
    Replies:
    3
    Views:
    1,926
    runescience
    Feb 7, 2006
  4. vyshu
    Replies:
    1
    Views:
    2,666
    Richard Senior
    Apr 27, 2007
  5. John
    Replies:
    0
    Views:
    983
Loading...

Share This Page