gpt4 book ai didi

java数组线程安全

转载 作者:行者123 更新时间:2023-12-01 20:26:55 25 4
gpt4 key购买 nike

java中的ArrayList是线程安全的,并且它是使用数组实现的。

那么,java中数组的访问是线程安全的吗?数组的访问需要同步吗?

最佳答案

不,ArrayList在 Java 中不是线程安全的。

来自the docs :

Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally.

你在想Vector吗? ,它在内部使用同步? (基本上每个方法都是同步的。)

关于java数组线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3737592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com