Is Java ArrayList / String / atomic variable reading thread safe?

前端 未结 6 1918
南方客
南方客 2021-02-14 00:27

I\'ve been mulling this over & reading but can find an absolute authoritative answer.

I have several deep data structures made up of objects containing ArrayLists, S

6条回答
  •  [愿得一人]
    2021-02-14 01:03

    The only reason why it wouldn't be safe is if one thread were writing to a field while another thread was simultaneously reading from it. No race condition exists if the data is not changing. Making objects immutable is one way of guaranteeing that they are thread safe. Start by reading this article from IBM.

提交回复
热议问题