Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not using Vector

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I am kindda confuse and to why you all say not using Vector. I mean the reason I would want to use Vector is it is synchorinized. Yep it is slower than List or ArrayList. Also ArrayList is not synchronized. So using Vector when we have to watch out for synchronization of data makes sense. Let me know!
-Amish
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at Peter's advice in this thread...
http://www.coderanch.com/t/231476/threads/java/Sync
You can use a vector, just be sure to use it right... although I would not recommend it.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amish,
You can create a synchronized version thus:

But you are usually better off just creating the List unsynchronized and protecting it by syncrhonizing the methods that access or modify it. I don't think thread-safety is a good enough argument to use a stale class when there are much better alternatives.
Just my dos centavos,
Michael Morris
[ August 05, 2002: Message edited by: Michael Morris ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic