Is Struts Action class Thread Safe?
Answers were Sorted based on User's Feedback
Answer / vijay
Struts 1 Actions are singletons and must be thread-safe
since there will only be one instance of a class to handle
all requests for that Action. The singleton strategy places
restrictions on what can be done with Struts 1 Actions and
requires extra care to develop. Action resources must be
thread-safe or synchronized.
Struts 2 Action objects are instantiated for each request,
so there are no thread-safety issues. (In practice, servlet
containers generate many throw-away objects per request, and
one more object does not impose a performance penalty or
impact garbage collection.)
Is This Answer Correct ? | 53 Yes | 16 No |
Answer / shakthi kumar
Action class is not thread safe, multiple threads will be
created for multiple requests to execute method, there is
no point in creating instance for each request. Also,
Action class is not a servlet, it just acts as an
intermediate between your business delegator (Action
Servlet) and your business layer only if designed properly.
Is This Answer Correct ? | 22 Yes | 6 No |
Answer / guddu
I think Struts Action class is not Thread Safe
For more of these, please visit
http://freesourceutilityhelp.googlepages.com
http://question2answer.googlepages.com
http://context2designpatterns.googlepages.com
Thanks
Is This Answer Correct ? | 23 Yes | 9 No |
Answer / styphy
In Struts-1x there will be only one instance of action
class. Hence it is not thread safe and the programmer has to
make sure that the code is thread safe.
In Struts 2x Action objects are instantiated for each
request, so there are no thread-safety issues. (In practice,
servlet containers generate many throw-away objects per
request, and one more object does not impose a performance
penalty or impact garbage collection.)
Is This Answer Correct ? | 14 Yes | 2 No |
Answer / bhanu prakash
It depends upon the usability, Struts action is a thread
safe if you are not using any Instance variable.
If you are using instance variable then it is not thread
safe.In this case you need to take extra precaution to
ensure the desired behaviour .( synchronization etc).
Is This Answer Correct ? | 7 Yes | 4 No |
Answer / shrikant kale
Basically ,ApplicationContoller/RequestProcessor will
create & use the only instance of each Action class [hence:
Singleton in nature] .
Also, it is not Thread-Safe as it suppose to serve the
multiple request.
Hence we must not declare class instance variable in Action
class.If declared so then Action class state becomes non-
thread safe.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / tipu swain
No Action classes are not Thread safe by default. But the Code written in the server or inside Struts software makes Action class as Thread safe and Singleton also..
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / shrikant kale
ApplicationContoller/RequestProcessor will create & use the
only instance of each Action class [hence: Singleton in
nature] .
Also the Action class has to handle the multiple request
(most of time simultaniously.) so it cant be Thread-Safe.
Hence we must not declare class instance variable in Action
class.If declared so then Action class state becomes non-
thread safe.
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / new user
Useful information about struts 1.x and struts 2
comparision:
http://struts.apache.org/2.0.14/docs/comparing-struts-1-and-
2.html
Is This Answer Correct ? | 2 Yes | 2 No |
Answer / ugandhar
Struts1 is not Thread Safe.
Struts2 is thread safe.
Is This Answer Correct ? | 2 Yes | 3 No |
kindly can any one post for me portlet,hibernate,spring example code and configuration,and some related tutorials plz its urgent for me....thanks in advance ............
What is struts.devmode?
How can we upload files in Struts2 application?
What is front controller in struts?
What do you mean by tiles in struts?
what is the purpose of action servlet and action?
What is Struts Frame Work Architecture(With Diagram) ?
How you will enable front-end validation based on the xml in validation.xml?
What is the use of interceptor?
What is struts framework?
Is Struts Framework part of J2EE?
What is the use of jsonvalidation in struts?