• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayList- How Safe to use in Jsp

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it a good practice to use Arraylist in jsp compared to vector and all other collection object ?

thanks
Mahendra
SCJP,SCBCD,ICED
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general I would say ArrayList is preferred to Vector.

I would just declare it as a List, as far as a JSP is concerned. That way it doesn't need to bother what the actualy implementation is.

Is it good practice? It depends what you are using the list for, and how you are using it.
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your data is not shared or read only, ArrayList would be sufficient. If you need to ensure thread safe access to your list, then Vector or other synchronized list (Like those provided in J2SE 5.0) would be more appropriate.

Definitely you can safely use ArrayList for concurrency access, provided that you implements all the necessary synchronization yourself correctly.
 
mahendra survase
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies fellows

Eddy Lee Sin �do you mean not sharing the data among other threads by not creating them in Declaration tag <%! %>.

Thanks
Mahendra
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your data is shared and you want a synchronized list, then just use Collections.synchronizedList(myArrayList), and voila - you have one.
IMO, Vector should be treated as deprecated, and only used when absolutely necessary - ie when imposed on you by someone elses API.


Declaring variables in <%! %> is NOT threadsafe.
However the better approach is to eliminate scriptlet code - don't declare any Lists at all - just use ones from the request/session/application attributes.
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic