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

前端 未结 10 2102
礼貌的吻别
礼貌的吻别 2020-12-16 11:05

Which Java Collections are synchronized, which are not?

Example: HashSet is not synchronized

10条回答
  •  自闭症患者
    2020-12-16 11:51

    Easy answer: not a single implementation of Collection is synchronized because synchronized is not a class property, it is only applicable to methods and blocks.

    I guess, you want to know which implementations are thread safe, which classes from the java collection framework can safely be used in a multithreaded environment.

    The information is always included in the javadoc (like here: Arraylist - which is not thread safe)

提交回复
热议问题