Need Fool Proof Synchronization of ArrayList in A Multi-threaded Environment

前端 未结 4 892
闹比i
闹比i 2021-02-15 15:33

I\'ve been at this for a week now doing my research on how to properly synchronize an ArrayList.

My main issue in a nutshell is I have a \"master\" ArrayList of objects.

4条回答
  •  无人共我
    2021-02-15 16:31

    Another approach is to protect all access to the list, but with a ReadWriteLock instead of synchronized blocks.

    This allows simultaneous reads in a safe manner, and could improve performance a lot in a scenario with many reads and few writes.

提交回复
热议问题