DEV Community

k@k
k@k

Posted on

Can we make array volatile in Java?

This is one of the tricky Java multi-threading questions you will see in the Interview.

Yes, you can make an array volatile in Java but only the reference which is pointing to an array, not the whole array.

What I mean, if one thread changes the reference variable to points to another array, that will provide a volatile guarantee, but if multiple threads are changing individual array elements they won't be having happens before guarantee provided by the volatile modifier.

Top comments (0)