• Post Reply Bookmark Topic Watch Topic
  • New Topic

newbie question about concurrency control  RSS feed

 
Sven Anderson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
 
Henry Wong
author
Sheriff
Posts: 22861
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!