簡體   English   中英

如何使非同步數據結構線程安全

[英]Ways to make non-synchronized data structure thread safe

我想知道除了使用像HashtableVector這樣的synchronized數據結構,或者使用像Collections.synchronizedList(List<T> arg)Collections.synchronizedMap(Map<K,V> arg)這樣的包裝器之外,還有其他方法可以使非同步數據結構成為線程安全的。 Collections.synchronizedMap(Map<K,V> arg)

我在面試中被問到如何使hashmap線程安全,我告訴他使用HashtableConcurrentHashMap或使用Collections.synchronizedMap包裝器,但是,看起來這些答案並不是他想要的

是的,你可以使它不可變 這實際上是在許多情況下使代碼線程安全的絕佳方法。

是。 如果您自己同步構建。 但出於明顯的原因,不建議這樣做......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM