
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Difference between Traditional Collections and Concurrent Collections in java
In Java as we know that Collections are one of most important concept which makes Java as a powerful language in itself. It is only support of collections in Java which make it to support any type of data in a convenient and efficient way along with possible CRUD operations over them.
But on same phase when collections get exposed to the multi-threading its performance get somewhat degraded because of somewhere collections lack the support to multi-threading environment. To overcome this limitation Java introduces Concurrent Collections which not only overcome the multi-threading environment limitation but also enhances the Java to perform with multiple threads data.
Following are the important differences between Traditional Collections and Concurrent Collections.
Sr.No. | Key | Traditional Collections | Concurrent Collections |
---|---|---|---|
1 | Thread Safety | Most of the classic classes in Java Collections such as Array List, Linked List, Hash Map etc. are not synchronized and are not thread safe in multi-threading environment. | On other hand Java introduces same classes in Concurrent Collections with implement synchronization in them which not only make these classes as Synchronized but also thread safe in nature. |
2 | Locking Mechanism | We have some synchronized classes in traditional collections as well such as Vector and Stack but these classes uses lock over whole collection which reduces performance and speed of execution. | On other hand concurrent collections introduces concept of partial locking where it locks only part of collection in case of multi-threading environment which improves the performance and speed of collections in such environment. |
3 | Runtime Exception | In case of traditional collections if we try to modify a collection through separate thread during collection iteration then we got Runtime Exception ConcurrentModificationException. | On other hand one would not get such exception if deals with the concurrent collections i.e. concurrent collections allows modification in collection during its iteration. |
4 | Preference | Due to reason mentioned in above points traditional collections are not preferred in multi-threading environment. | On other hand Concurrent collections are primarily preferred in multi-threading environment. |
5 | Introduction in market | Traditional collections are type of legacy collection in Java and are introduced before concurrent collections. | While concurrent collections are introduced in JDK 1.5 i.e. are introduced after traditional collections. |
- Related Articles
- Difference between collection and collections in java
- Difference between next() and hasNext() in java collections?
- Difference between Streams and Collections in Java 8
- Differences between Collection and Collections in Java?
- Multidimensional Collections in Java
- Collections in Java\n
- Java Lambda Expression with Collections
- Collections in C#
- Difference between Concurrent hash map and Synchronized hashmap in Java
- Indexed collections in JavaScript
- Keyed collections in JavaScript
- How to initialize immutable collections in Java 9?
- Get Enumeration over ArrayList with Java Collections
- Shuffle elements of ArrayList with Java Collections
- Swap elements of ArrayList with Java collections
