This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Not using Vector  RSS feed

 
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
 
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.
 
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
Boost this thread!