Vector is synchronized but ArrayList is not synchronized but we can synchronize an ArrayList by Collections.synchronizedList (aList), so which will perform better and faster
A:
This is not an answer per se, but an interesting read in the related topic.
Deadlocks through Cyclic Dependencies (using Vectors or synchronized list)
Tony Chen
2010-06-22 18:14:16
one more: Serialization Size of Lists (Vector vs. ArrayList vs. LinkedList) http://www.javaspecialists.eu/archive/Issue183.html
Tony Chen
2010-06-22 20:27:18
Since this is not a forum, it would be appreciated that you post sidenotes like that as a comment to the question, not as an answer. Thank you. Interesting links though. I think i have been using Dr. Kabutz's way to calculate object sizes for some years now.
Stroboskop
2010-08-23 13:13:23
+1
A:
Synchronized collections are a waste of time. A trivial example why it is bad is to consider two threads running a loop doing something to a collection:
int i = 0;
while (i < list.size())
{
if (testSomeCondition(list.get())) {
list.remove(i);
else
i++;
}
This would break horribly whether the collection was sychronized or not. It is better to synchronize any action that occurs on the collection or use Java 5 concurrency Locks to do the same
synchronized (list) {
int i = 0;
while (i < list.size())
{
if (testSomeCondition(list.get())) {
list.remove(i);
else
i++;
}
}
locka
2010-08-23 12:57:11