Java基础---为什么我们需要并发集合?

As we already know Collections which is nothing but collections of Objects where we deals with the Objects using some pre-defined methods. But There are several problems which occurs when we use Collections concept in multi-threading. The problems which occurs while using Collections in Multi-threaded application:

  1. Most of the Collections classes objects (like ArrayList, LinkedList, HashMap etc) are non-synchronized in nature i.e. multiple threads can perform on a object at a time simultaneously. Therefore objects are not thread-safe.(大多数的集合类都不是线程安全的)
  2. Very few Classes objects (like Vector, Stack, HashTable) are synchronized in nature i.e. at a time only one thread can perform on an Object. But here the problem is performance is low because at a time single thread execute an object and rest thread has to wait.
    (虽然Vector,Stack,或者 HashTable是线程安全的,但是他们在同一时间只允许一个线程访问,其他的线程就会被lock住,在性能上不好)
  3. The main problem is when one thread is iterating an Collections object then If another thread try to modify the content of object then we will get RuntimeException saying ConcurrentModificationException.
    (当一个线程在使用iterator遍历一个集合的时候,如果集合的内容被其他线程修改,就会抛出并发修改的异常,这也令人头疼)

Because of the above reason Collections classes is not suitable or we can say that good choice for Multi-threaded applications.
To overcome the above problem SUN microSystem introduced a new feature in JDK 1.5Version, which is nothing but Concurrent Collections.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值