Which Java Collections are synchronized(thread safe), which are not?

Thread safe Collections –

  1. ConcurrentHashMap

Thread safe without having to synchronize the whole map
Very fast reads while write is done with a lock
No locking at the object level
Uses multitude of locks.

  1. SynchronizedHashMap

Object level synchronization
Both read and writes acquire a lock
Locking the collection has a performance drawback
May cause contention

  1. Vector

  2. HashTable

  3. CopyOnWriteArrayList

  4. CopyOnWriteArraySet

  5. Stack

Rest all are not thread safe

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)