volatile array elements are not volatile

There is no way in Java for an arrays elements to be volatile.

Tried using the concurrent AtomicReferenceArray for a matrix (array-of-arrays), but wasn't impressed with the resulting implementation.


private volatile
AtomicReferenceArray<AtomicReferenceArray<Foo>> foos;
...
foos = new AtomicReferenceArray<AtomicReferenceArray<Foo>>(xSize);
for (int x = 0; x < foos.length(); x++) {
foos.set(x, new AtomicReferenceArray<Foo>(ySize));
}
...
Foo foo = foos.get(x).get(y);
...
foos.get(x).set(y, foo);


A customized thread-safe encapsulation of the data matrix with indexing accessors and mutators is a cleaner implementation.

Comments

Popular posts from this blog

Sites, Newsletters, and Blogs

Oracle JDBC ReadTimeout QueryTimeout

Locks held on Oracle for hours after sessions abnormally terminated by node failure