Help coderanch get a
new server
by contributing to the fundraiser
  • 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

Q about JSP (1): use of Vector in JSP

 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Given a website where at a certain point in time a
dozen of users are connected that just want to view
a list of data. This data is extracted from the database
and presented by a JSP page. Suppose the JSP page builds
the page and presents the data in tabular format by
iterating through a Vector that originated from the classes
handling database connection and queries and contains
the data records in the form of objects.

My question is: is the choice of the Vector as a collection
type overkill since it�s synchronized? My impression is that
when a user sees the data he/she asked for, any thread dealing
with the Vector for presentation purposes (i.e. creating the
html formatted data) won�t be holding any locks anymore after
this operation has ended. Additionally different users of the
same website don't interfere in these operations.
Therefore no thread interferes with another, making
synchronization unnecessary.

What do you think?


Cheers,

Gian Franco
[ June 30, 2004: Message edited by: Gian Franco Casula ]
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the Collection that holds the data should be a local variable in the _jspService method because local variables are threadsafe for JSP. Also, I would say that a non-synchronized ArrayList would be better for your purposes than a Vector. Usually, you use synchronized collections when multiple threads are attempting to make concurrent modifications.
 
This one time, at bandcamp, I had relations with a tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic