Hi Anmitra,

SingleThreadModel implementation is server dependent, an implementer
has the options of synchronizing all access to the servlet, maintaining
a pool of servlets, allocating a servlet per thread, or even allocating
a servlet per request.  Although a the best model is to maintain a
servlet per thread (because it requires no synchronization), I would not
necessarily depend on the behaviour for an arbitrary vendor.

That said, you should be able to access session state with impunity,
meaning that individual accesses will be thread-safe.  However, if the
manipulations you are making to the session-state are not idempotent
you may want to protect accesses with synchronization on the session
object itself since theoretically the user could hit your servlet
many times with the same browser if they reload before the servlet
is done executing.  You won't be able to do even this in the distributed
case, to ensure correct behaviour always use sessions in an idempotent
fashion.

Also, you didn't mention this as a consideration, but your sessions in
many servers can be made to be fault-tolerant, while it is unlikely you
will get this behaviour by storing the information in your own classes,
at least not without a lot of effort.

Sam

> Hi
> Can anyone suggest which one is better in terms of performance ---
> maintaining a pool of servlets using Single ThreadModel or just keep the
> servlet as it is ie only one instance. I understand that the
> answer depends
> on whether to make ur servlet thread safe or not. I am just not
> getting when
> u actually need to make the servlet thread safe --- as such the
> servlet will
> never have any private data --- what it will do in doGet or doPost is to
> mutate the session info --- which is global --- in this scenario
> do we need
> synchronized access to the session object??? I dont think we need as the
> servlet is mutating the session particular to that request. The
> code will be
> something like this
>
>  doGet(.......)
>  {
>        HttpSession h = req.getSession(false); // Session has been already
> created in the login servlet say.
>        h.put(....);
>        ....
>  }
>
> Question is do we need to synchronize this particular block of code??? If
> not the when do we need SingleThreadMode or rather when do we
> need to make a
> Servlet thread safe(any examples ..). Any pointers are welcome.
> TIA
> Anamitra
>

___________________________________________________________________________
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