I am stuck with the situation where :
A new object is instantiated with an array of size n
of unset references (null
).
A build step should assign each index a reference exactly once and then returns the full-filled array.
The complexity is that the array is feeded in parallel by multiple threads.
I don't care with the atomicity of the set operation because two threads can't access the same index, however, I would like to be sure that the thread that returns the filled array "sees" every index filled.
private final String[] arr = new String[n];
private void parallelFeed() {...} // Multi-threaded
public void build() {
parallelFeed(arr);
return arr;
}
Should I use an AtomicReferenceArray
?
Thanks a lot for your help