• 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

newbie question about concurrency control

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've got the following newbie question about concurrency control. I just need someone to confirm that my reasoning is correct for the following scenario.

Local variables declared within methods are thread-safe and don't impose any problems when multiple threads accessing the same instance of an object. Now I've declared and instantiated a ValueListHandler object within a method which is a mutable object hence not thread-safe. As long as I use this ValueListHandler within this method and never expose it anywhere else. I assume I should be safe from threading issues even though the ValueListHandler itself isn't thread-safe. Am I right in thinking this?

Many thanks
S
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't make the conclusion without taking a look at the class. For example, it is possible for this instance of the class, which is only accessible from the method, to have static variables. If these static variables are changed, it will affect all copies of the instances of the class. And vice-versa.

Henry
 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

That's true, if the ValueListHandler had static members I wouldn't be safe. In this case the ValueListHandler is made up of a private List instance, a few private String variables, setter/getter methods and a method which add elements to the List. Am I still safe in using the ValueListHandler within the executing method?

Thanks
S
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic