Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

threads and collections  RSS feed

 
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
Sheriff
Posts: 36406
454
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
Sheriff
Posts: 36406
454
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!