File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads & Helper Class

 
Paul Woods
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
TIA,
Paul
 
Junilu Lacar
Bartender
Pie
Posts: 6529
21
Java Linux Mac Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic