• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

why to use arraylist instead of vector in web applications?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when it comes to the difference in ArrayList and Vector, it is said that Vector is synchronised while ArrayList not..
But still i have seen the implementation of ArrayList in Web Applications, though it is preferred to use Vector in multi-threaded applications.
How do we achieve synchronization in such applications by using arraylist??
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The major reason for using ArrayList is the performance factor. If we use Vector then the app becomes slow bcs Vector is synchronized and canot be accessed by multiple threads concurrently. The point of confusion for you is "in web apps why do we use ArrayList even though we have multiple threads accessing the ArrayList ? " and the answer is as stated above. But if there is a possiblity that multiple threads will try to modify(write) the value of an arrayList (rather than just accessing(read)it) , then it's better to use a Vector or synchronize the block of code where the modification is done ,which ever is relevent to the situation.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pooja Malhotra, welcome to the Ranch.

Aslam Parveez is quite right about why you use ArrayList instead of Vector.

. . . and if you look in the API spceification for ArrayList it tells you what to do about synchronisation.

CR
 
pooja malhotra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks!!..i think that gives a relevant answer to my query..
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You never need to Vector/Hashtable, you can get the same benefit using ArrayList/HashMap if you synchronize the methods that access these objects. Therefore, these classes give you more flexibility over the original implementations.
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm beginning to suspect there are lots of old books floating around out there.

Its really simple. ArrayList is the newest thing. Vector is over and done with. Going forward support will be given to improving ArrayList usefulness but no more for Vector.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And be aware that you rarely need to synchronize anything a properly written web application.
 
Campbell Ritchie
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The API specification is your friend. This is where you should be looking all the time.

It doesn't say that Vector or Hashtable are deprecated; both classes will still work.
If you look at some other classes, however, you will find them marked as deprecated, eg StringTokenizer, which it specifically describes as legacy code (but it will still work), and methods like Thread.stop, where there are dire warnings against using it at all.
 
I found a beautiful pie. And a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic