This week's book giveaway is in the Cloud forum.
We're giving away four copies of The Business Blockchain and have William Mougayar on-line!
See this thread for details.
Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • 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 ]
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic