本文介绍了就是Java的ArrayList /字符串/原子变量读线程安全的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经超过放大器琢磨这一点;读书,但可以找到一个绝对权威的答案。

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

我有由包含的ArrayList对象的几个深的数据结构,字符串和放大器;原始值。我可以保证,在这些结构中的数据不会改变(没有线程将做清单,变化的参考,变更原语的结构性变化)。

I have several deep data structures made up of objects containing ArrayLists, Strings & primitive values. I can guarantee that the data in these structures will not change (no thread will ever make structural changes to lists, change references, change primitives).

我想知道如果在这些结构中读取数据是线程安全的;即是安全的递归从对象中读取变量,迭代的ArrayList等提取的多线程结构信息不同步?

I'm wondering if reading data in these structures is thread safe; i.e. is it safe to recursively read variables from the objects, iterate the ArrayLists etc. to extract information from the structures in multiple threads without synchronization?

推荐答案

为什么它不会是安全的唯一原因是,如果一个线程被写入到一个领域,而另一个线程同时被从中读取。如果数据没有改变没有的存在。使物体不可变的是保证他们是线程安全的一种方式。通过阅读的文章开始。

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.

这篇关于就是Java的ArrayList /字符串/原子变量读线程安全的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:28