Am Freitag, 3. Januar 2003 09:56 schrieb Vikramjit Singh:

> > -----Original Message-----
> > From: Eric Noriega [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, January 03, 2003 1:31 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: Use of Vector
> >
> >
> >     This is totaly false.  You do need to worry about
> > threading, if the
> > variable is static to the class (not instance).

Yes. The scheduler can take away control any
time, regardless of a variable being static or
not. Considering static variables, this is what
class locks are meant for. RTFM, one might
be tempted to say. Or get certified, if this
is an option. You won't pass if you don't
know Java threads in and out.

> Yups thats true, that when a variable is static, and two threads are
> accessing the static variable then the value of the variable can be
> changed. But my dear, what i am saying is that in web applications, the
> container takes part of the threading issues for you, and where every user
> has got a different session for him.

Sorry, but this is *utterly wrong*. Unlike the J2EE tier (where
the 'synchronized' keyword is even forbidden), the *web container*
doesn't care about thread safety at all. It's entirely the program-
mer's responsibility to take care of all threading issues. Further-
more, this has nothing to do with Sessions, too. In fact, the
opposite is true. Even within a session, a user can happily
send multiple requests to the web tier which are then
executed as different threads by the JSP rsp. servlet
instance. 

> >Even a vaiable in the
> > session could be accessed by two threads.

Yes. In JSP terms, only the page and request scopes are
safe. Session and application scopes are not.

> What exactly do you mean by session could be accessed by two threads?

Open another window in Explorer and see for yourself.

> >Also I've seen some poeple
> > mention not to use Vector because it is "old".  This is also not true,
> > Vector can be useful and is not depricated at this time.

In opposition to some opinions I've read here, I think using a
Vector is quite state-of-art. Vector is the synchronized equiva-
lent of ArrayList and a Collection now. I don't see any advantages
in using techniques to make an ArrayList behave as if it were a
Vector. Considering "old": in the beginning, there were no
Collection classes at all. There were only Vector, Hashtable and
Java arrays. Then they introduced the Collection classes, first as
an optional package, later being integrated into the J2SE core.
Nowadays, a Vector is just another Collection type, and a 
thread-safe one. If you have a proper design and code against
interfaces, you can easily exchange the specific implementa-
tion by something better suited, a linked list implementation
of the Collection interface, for example. This entirely depends
on your concrete application. If doing so, and the Collection
chosen is not thread-safe by itself, you may use static
helper functions to deal with that issue, if necessary. If
Vector or Hashtable suffice, just stick to these. 

> Vector has its own uses, and I dont see down the lane also vector being
> deprecated.

Unless someone comes up with a real good reason some day, this
definitely is true.

HTH,

-- Chris (SCPJ2)

-- CLIP! (some whole lot of stuff)

==========================================================================To 
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to