Is java.util.Hashtable thread safe?

后端 未结 9 1280
名媛妹妹
名媛妹妹 2020-12-09 06:23

It\'s been a while since I\'ve used hashtable for anything significant, but I seem to recall the get() and put() methods being synchronized.

The JavaDocs don\'t ref

9条回答
  •  无人及你
    2020-12-09 06:59

    Note, that a lot of the answers state that Hashtable is synchronised. but this will give you a very little. The synchronization is on the accessor / mutator methods will stop two threads adding or removing from the map concurrently, but in the real world you will often need additional synchronisation.

    Even iterating over a Hashtable's entries is not thread safe unless you also guard the Map from being modified through additional synchronization.

提交回复
热议问题