File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts and Thread safe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and Thread safe" Watch "Struts and Thread safe" New topic

Struts and Thread safe

Alexandre Baldo
Ranch Hand

Joined: Aug 04, 2006
Posts: 48
Hello, guys!

I was thinking about thread safety and..
I know that when you're working with Servlets and JSP's (without a framework) you have to take care of thread safety yourself.
For instance, if I have an application scoped attribute I know I have to synchronize that attribute to avoid multiple access on it.
But the question is...
Does Struts take care of it, or do I have to do the same work with my variables or attributes in the framework?

I'm asking this becouse I'm working on a big system that uses Struts as the framework and I never saw any synchronized code protecting these attributes in the entire application.
I think it's wrong...

Can anyone help me!?


-> Sorry for the English. I'm still learning... :-)

SCWCD 1.4<br>
SCJP 1.4
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi Alexandre.

Struts does not automatically protect you against thread-safety issues. As you said it yourself, if you have an object in your application that is somehow shared by different threads, you might need to synchronize access to it. Regarding Struts (or other frameworks) you should be aware of how they work and their micro-architecture so you don't insert flaws into your design. For instance, it is not a good idea to put data members in Struts action classes (there's no guarantee about their thread-safety because Struts might use the same action instance for distinct requests).

Leandro Melo
SCJP 1.4, SCWCD 1.4
Alexandre Baldo
Ranch Hand

Joined: Aug 04, 2006
Posts: 48
Valeu, Leandro!
I agree. Here's the link:
subject: Struts and Thread safe
It's not a secret anymore!