Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Arraylist vs Vector  RSS feed

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
need to have some kind of clear understanding regarding the synchronized behavior of arraylist and vector. when we say that Vector is synchronized and arraylist is not, does it mean that
1. when multiple threads access vector and modify its contents, one thread will see updated copy of the vector before modification
2. when multiple threads access arraylist and modify its contents, one thread will see updated copy of the arraylist before modification only if the arraylist is properly synchronized.

is there anything more than what I said?

Regards,

 
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

nitinram agarwal wrote:Hi,
need to have some kind of clear understanding regarding the synchronized behavior of arraylist and vector. when we say that Vector is synchronized and arraylist is not, does it mean that
1. when multiple threads access vector and modify its contents, one thread will see updated copy of the vector before modification
2. when multiple threads access arraylist and modify its contents, one thread will see updated copy of the arraylist before modification only if the arraylist is properly synchronized.

is there anything more than what I said?

Regards,



I found a related article. Might be explaining more than just Synchronization issue. If you have access to the source code for Vector and ArryaList implementation it will be lot helpful to see how the methods- which modify the list contents are implemented.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The methods on the Vector are synchronized meaning that only 1 thread can access it at a time. But a couple of successive method calls need external synchronization (e.g. checking if an element exists and if not inserting it).

So it's not who sees what but who can access the object.
 
nitinram agarwal
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so you mean even multiple threads cannot read the vector simultaneously. I was under the impression that its exlusive modification on the vector.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it's also an exclusive read. Otherwise it's not properly synchronized.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!