Thread Safe Issue with Servlet

I saw the following statement in one of the J2EE compliant server documentations:

"By default, servlets are not thread-safe. The methods in a single servlet instance are usually executed numerous times simultaneously (up to the available memory limit)."

I'm quite concerned with this statement for the primary reason that (I'm trying to reason by reading it out loud) servlets are not going to be thread-safe especially when available memory hit really really low!! So, when the application is still having sufficient memory, we will not likely run into concurrency problems, i.e the happy scenario for a short period after server is started. BUT, good things don't last long.. Anyway, hope someone can explain to me with more insights. Thanks.

[766 byte] By [say-haua] at [2007-9-19]
# 1

Don't worry, memory occupation and thread safety are not related at all.

In my opinion, the following is the meaning of the statement you quote.

Since the servlet specification doesn't force any implementation to spawn a new servlet object upon each request (and this should be a real memory hit!), nor to synchronize calls to servlet methods, you should always code your servlet in a "stateless" fashion: you should be aware the same method on the same object could (and probably will) be called concurrently if multiple concurrent client requests are submitted.

Hope I've been clear enough...

jummoMa1a at 2007-7-8 > top of java,Core,Core APIs...
# 2
Thanks man, i also did some codings to testing this out. Both your comment and my testing cleared my doubt :)
say-haua at 2007-7-8 > top of java,Core,Core APIs...
# 3
If you need thread safe data storage in a servlet, you can use the ThreadLocal class. If you need to keep data on a per-client data between servlet calls, use the session object obtainable from the request object.
armalcolma at 2007-7-8 > top of java,Core,Core APIs...