在Java中,它是写同步访问数组如果需要每个线程写入到一个单独的单元格的空间? [英] In Java, is it required to synchronize write access to an array if each thread writes to a separate cell space?

查看:233
本文介绍了在Java中,它是写同步访问数组如果需要每个线程写入到一个单独的单元格的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是,如果每个线程写入到一个单独的单元格空间,在Java数组的写访问同步需要它?

Is it required to synchronize write access to an array in Java if each thread writes to a separate cell space?

编辑:具体而言,该阵列可以是一个基本类型数组或不可变对象数组。防爆。 int数组或一个字符串数组。

Specifically, the array is either a primitive Array or an immutable object array. Ex. An int array or a String array.

推荐答案

没有,不需要同步。

据在 JLS§17.6字撕裂

一个实施考虑Java虚拟机是每一个领域,数组元素被认为是不同的;更新一个字段或元素不能与之交互读取或任何其他方面或元素的更新。特别是,两个线程是单独更新一个字节阵列的相邻元素必须不干扰或相互作用,不需要同步,以确保连续的一致性。

One implementation consideration for Java virtual machines is that every field and array element is considered distinct; updates to one field or element must not interact with reads or updates of any other field or element. In particular, two threads that update adjacent elements of a byte array separately must not interfere or interact and do not need synchronization to ensure sequential consistency.

这篇关于在Java中,它是写同步访问数组如果需要每个线程写入到一个单独的单元格的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆