Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we use vector in single thread application?  RSS feed

 
kumaresan Natarajan
Greenhorn
Posts: 27
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to create a vector in single thread application ? is it possible ?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. why not? But here its better to use ArrayList instead. Its faster.
[ August 08, 2005: Message edited by: Adeel Ansari ]
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use either Vector or ArrayList in a single- or multi-threaded application. It's just that in a multi-threaded app you need to take care to synchronize concurrent accesses to ArrayList, while Vector is inherently threadsafe.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually write your code against the List interface
another thing is if there will be concurrent threads, just use Collections' Decorator around the object of interest.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class can not be considered thread safe. Only a usage can be considered thread safe or thread unsafe. Therefore, vector is NOT inherently thread safe. And this is why nobody should use Vector or Hashtable anyway. And thats why we have replacement classes for both. Where you syncornize will depend on your usage. Its highly unlikely the synchronization provided by Vector will be sufficient or efficient.

I just don't know why Sun didn't state it this way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!