This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Thread Safe - Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Thread Safe - Struts" Watch "Thread Safe - Struts" New topic

Thread Safe - Struts

Akhil Chauhan

Joined: Jan 06, 2009
Posts: 2
Hi All,

Struts1 Action classes are not thread safe & instantiated only once.
So each request will access the same object.

Small Doubt -
If every request acess the same object.
What about the object inside the action classs, they will b instantiated per request or even they will behave same as Action class.
Ex -
List lst = new ArrayList();

Here -
ArrayList object wil be instantiated per request ?

Joe Ess

Joined: Oct 29, 2001
Posts: 8836

The code you have above has a variable in instance scope. There is one instance of that variable created for each instance of ActionClass, not for each request.
Have a look at the Action Class Design Guidelines

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Akhil Chauhan

Joined: Jan 06, 2009
Posts: 2
thanks Joe
It is sorta covered in the JavaRanch Style Guide.
subject: Thread Safe - Struts
Similar Threads
class variable safe in struts 2 action ?
struts2 modeldriven unable to transfer form data to model object
action class instance
thread safety of helpmer methods in ejb
multithreading in struts...