Fabrizio Gianneschi<br />SCPJ2, SCWCD, SCBCD
Originally posted by Fabrizio Gianneschi:
ActionServlet is a servlet, so each request is served by a separate thread (except if you use the SingleThreadModel).
As I know, each thread creates new Action and ActionForm instances, so there're no concurrency problems.
They can occur only if you write unsynchronized static properties or methods on Action classes.
I'm sure the author could be more precise.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Originally posted by David Hibbs:
b) The action servlet creates action instances as they are requested... but only ONE instance for each path. Thus, Action subclasses MUST be thread-safe or you'll get some very odd results!
From Struts Documentation: http://jakarta.apache.org/struts/api/org/apache/struts/action/ActionServlet.html
"The standard version of RequestsProcessor implements the following logic for each incoming HTTP request. You can override some or all of this functionality by subclassing this object and implementing your own version of the processing.
1) Identify, from the incoming request URI, the substring that will be used to select an action procedure.
2) Use this substring to map to the Java class name of the corresponding action class (an implementation of the Action interface).
3) If this is the first request for a particular Action class, instantiate an instance of that class and cache it for future use.
4) Optionally populate the properties of an ActionForm bean associated with this mapping.
5) Call the execute method of this Action class, passing on a reference to the mapping that was used, the relevant form-bean (if any), and the request and the response that were passed to the controller by the servlet container (thereby providing access to any specialized properties of the mapping itself as well as to the ServletContext). "
Fabrizio Gianneschi<br />SCPJ2, SCWCD, SCBCD
Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
Originally posted by Timothy Toh:
How about the Form class ? How many gets instantiated ? I guess it should be X number of Form instances if there are X number of requests. This is because each form needs to carry different values. Is my guess right ?
Originally posted by David Hibbs:
Form instances are created based on the scope associated with the action.
scope=session: One form instance per session.
scope=request [default]: One form instance per request.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Originally posted by Fabrizio Gianneschi:
Now I'm wondering WHY Struts programmers wrote a RequestProcessor with this behaviour , it's for sure an optimization (and a good one, I think) but it complicates the approach to the framework to newbies that don't know anything about threads.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Originally posted by David Hibbs:
Why should Struts try to do something different from what the Servlet Engine or J2EE spec do?
Fabrizio Gianneschi<br />SCPJ2, SCWCD, SCBCD
although it is generally the case that you would have only one instance of an Action class, you shouldn't count on this since the web container itself may create more than one instance of a Servlet to improve performance
MSc Electronics, ICT
Something about .... going for a swim. With this tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|