So if a program does this:
static ArrayList<X> a = null;
static{
for(;;){X x = new X(); a.add(x)}
}
and the only operations called after the static initializing, on the shared list, are get() and x.t()
X x = a.get(i); x.t();
and X doesn’t have access to container & is thread safe, that should mean that using Arraylist like this, without synchronization is thread safe, correct?
If nothing is modifying the
ArrayListthan there is no reason that you should be worried about it’s thread-safety.That static block is thread-safe by default, because it’s ran only once when the class is loaded (for initialization).