What does it mean when we say Hashtable or Vector is synchronized?

后端 未结 4 867
借酒劲吻你
借酒劲吻你 2020-12-30 14:27

The questions says it all, just wondering, in an interview, what would you say when they ask you, \"What does it practically mean by Hashtable or Vectors being synchronized?

4条回答
  •  一生所求
    2020-12-30 14:32

    Practically it means two things:

    1. Don't use them unless you will be sharing them between threads (if not just use HashMap or ArrayList).
    2. If you are sharing them between threads, check that the synchronization policies they implement actually are sufficient to make your program threadsafe (because the existence of some synchronization is little indication of the all-round concurrent behaviour of a class).

提交回复
热议问题