I was trying to understand why vector in Java has to be synchronized. Wherever I reached through google, they said that its synchronized because its elements are synchronized blocks other threads to access when one thread is accessing it. But what I really want to know is why it has to be? Java should have left it to the people who are accessing it. But why Java forced all the people accessing vector to use a synchronized data structure? I agree with people who says that ArrayList can be used for my requirement. But my point is what is that vector is going to give me??
Thanks and regards,
Vector was part of JDK 1.0;
ArrayList was not. We learned that synchronization as a default meant poor performance, so it was reversed when the Java Collections API came out.
You can still choose to synchronize any collection you need to using methods in
java.util.Collections, but it's your choice.
You should also be aware of the collections that are part of the
java.util.concurrent packages. Simultaneous access of collections certainly needs to be choreographed carefully.