• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads & Helper Class

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic