I was reading about Java's collections and then I read this line:
"None of the collection classes are synchronized, but as you will see later in this chapter, it is possible to obtain synchronized versions."
Can anyone tell me what is the difference between synchronized and non-synchronized collections in Java?
In Synchronization, If we are executing something then we need to wait for it to finish before moving to the another task.
Collection classes are not synchronized by default. The collection object is mutable that means once creating the object and that object is calling two threads at a time but one thread is changing the value of the object then it can be effected by another object. So, it is not thread safe.
We can explicitly synchronized collection using static method java.util.Collections.synchronizedCollection(Collection<T> c)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With