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

Threads & Helper Class

Paul Woods

Joined: Nov 15, 2002
Posts: 23
I have a helper class that I pass values in and out of, including an ArrayList. This helper class is only written to using the Execute() method of an Action class. When I am done with this helper class in a particular request, it is saved back to the Session.
Is the above thread safe? I know that ArrayLists by themselves are not, but I am only accessing it from a method - not as an instance variable. Does that matter?
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

In this case, I think it could although the likelihood of it being a problem is probably very low.
Since the object comes from the session collection, it becomes a "shared" resource in the session scope. Your local variable is really just a reference to the shared object. Is it likely that there will be multiple threads running for the same session, i.e., could the user, using the same session, submit multiple requests to the same action (this situation might occur is you use an automated testing tool that simulates concurrent access to your website)? Does your action spawn new threads that access the session and that particular helper object? If so, then you may need to synchronize. If not, then you'll probably be all right.

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: Threads & Helper Class
It's not a secret anymore!