instance variables in struts action classes

J

javadude

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
 
O

Oscar kind

javadude said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top