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 |
Which class is the Front Controller in Struts2?
what is the purpose of action servlet and action?
What is the purpose of @urlvalidator annotation?
what is a RequestProcessor?
Is Struts Framework part of J2EE?
How client side validation is enabled on a jsp form?
What happens when Two users requests for same action class? How the threads are controlled?
we have two applications A1 & A2 both are accesing the same databse table employee at the same time how we will manage this so that both application can get the correct no of emloyee while A1 is inserting a employee at the same time while other applicatuion is getting the empployee list.
Is struts mvc framework?
What is the purpose of struts.properties in struct2?
What do you mean by tiles in struts?
how can u handle run time exceptions in struts and jsp plz explain briefly not single word answer?