views:

308

answers:

2

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
one more: Serialization Size of Lists (Vector vs. ArrayList vs. LinkedList) http://www.javaspecialists.eu/archive/Issue183.html
Tony Chen
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
+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