splinter123
splinter123

Reputation: 1203

Accessing different list elements in different threads

Is it thread-safe to access (read/write) different elements of the same ArrayList from different threads, when no add/remove operations are performed on the list and every thread accesses a fixed set of indexes which do not intersect among threads? I see no need to use particular precautions here (like locking blocks), but I just wanted to be sure: can something possibly go wrong?

Upvotes: 1

Views: 101

Answers (1)

user2717954
user2717954

Reputation: 1902

no. as long as no removes or adds are done the array won't be resized (and thus recreated) and each get(i) call will be safe

Upvotes: 1

Related Questions