As a starting point ,is it right to state that to keep a
servlet 'thread-safe' I should stay away from having servlet
class variables? Else I would have to worry about locking
those variables when I use them in my servlet... Right?

How 'bout my database connections?  If I use a connection
pool, as described in many serlet books, am I then
'thread-safe'?

Carlos Herrera
[EMAIL PROTECTED]



At 12:40 18/10/99 -0500, Li Xu wrote:

>there's been some discussion about servlet session these days on this mailing
>list. I am confused with the difference between session and thread. Can
anybody
>explain it to me?

They are not really connected. A thread is a Java thread - a single thread
of execution taken by a program - and is not specific to servlets.  A
session is a means of associating requests from the same browser.

There will normally only be one instance of your servlet class created, and
for each connection to it from a browser, a different thread is used
(normally from a pool of threads). That means the same object may be being
used by multiple different threads at the same time (hence the requirement
to keep your servlets 'thread-safe' - i.e, stop one thread from trampling
on another's data).

A session, as mentioned, is a means of associating requests from the same
browser. HTTP is a stateless protocol, which means in simple language that
you issue a request, get a response and that's it. If you issue another
request, it doesn't know anything about the previous one. But in real world
use, particularly for things like e-commerce, you want to be able to have a
series of related transactions. A session is a means of doing this.
Normally by sending back a cookie to your browser, your servlet engine is
able to have the concept of a group of related requests.

Hope this helps!

John Moore
==================================================
John Moore ~ Norwich, UK  ~ [EMAIL PROTECTED]
==================================================

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to