"are arrays thread-safe in java?" Code Answer


while you will not get an invalid state by changing arrays as you mention, you will have the same problem that happens when two threads are viewing a non volatile integer without synchronization (see the section in the java tutorial on memory consistency errors). basically, the problem is that thread 1 may write a value in space i, but there is no guarantee when (or if) thread 2 will see the change.

the class java.util.concurrent.atomic.atomicintegerarray does what you want to do.

By PyPiePi on February 16 2022

Answers related to “are arrays thread-safe in java?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.