Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

threads and collections

 
Larry Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are collections created inside a method thread-safe? I know they are local variables, but are collections different?

for example:

Class a {

public Set meth() {
Set set = new HashSet();
set.add(new Integer(1));
return set;
}

}

Is set thread-safe?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35753
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java yes yes",
We're pleased to have you here with us in the threads forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Forum Bartender
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35753
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The set is still only accessible by one thread since it is a local variable. So you don't have to worry about concurrency issues.
 
Larry Jones
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the heads-up about the naming policy and the nice answer to my question.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!