Let's consider this situation:
public class A {
private Vector<B> v = new Vector<B>();
}
public class B {
private HashSet<C> hs = new HashSet<C>();
}
public class C {
private String sameString;
public void setSameString(String s){
this.sameString = s;
}
}
My questions are:
Vector
is thread-safe so when a thread calls over it, for instance, theget(int index)
method Is this thread the only owner ofHashSet
hs?If a thread call
get(int index)
over v and it obtains one B object. Then this thread obtains a C object and invokesetSameString(String s)
method, is this write thread-safe? Or mechanism such asLock
are needed?