• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification On Vector.  RSS feed

 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Folks,

I've got a doubt the way a Vector operates in Java. Let's just say we are using a Vector and we all know for a fact that Vector's are synchronised. But does it synchronise each individual method? I mean rather than synchronising a whole sequence of operations does Vector synchronise each and every operation when we iterate over a Vector?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's what it means. Each of the methods is synchronized.
 
Vineeth Menon
Ranch Hand
Posts: 79
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I guess using the ArrayList with Collections.synchronizedList() is always loads better than Vector eh?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only in the sense that Vector has been obsolete for new programming for at least 10 years. As for a "synchronized" collection where every method is synchronized, that just leads the unwary programmer to believe that it's totally thread-safe and it isn't necessary to worry about synchronizing access to the "synchronized" list. You just need to read the documentation for Collections.synchronizedList, where it explains why just synchronizing every method isn't sufficient.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!