>>> Ted Stockwell <[EMAIL PROTECTED]> 10/4/99 4:11:19 PM >>>
> My senior programmer put me 2 questions w.r.t. threads, servlets
and the
> servlet engine.
Firstly the answers can be found... mostly in the spec.
Secondly is this individual a doubter of the true path to
server-wisdom? Does he (gasp!) use MicroTo$$ products? 8->
> 1. Suppose unloading or terminating the servlet by calling its
destroy()
> method is going to cause a threading issue. We have to wait
>until all the threads currently executing in the service() methods
of the
>servlet to finish before destroying and releasing resources. Lets
> assume that we alsol keep a count of the number of threads in the
> service() methods and use a flag as given in the online Java
Tutorial.
> Question: Even though we do this, how can we prevent new requests
from
> entering the service() methods even after the destroy() method is
> called. This could mean that the servlet is never unloaded???
Ted wrote:
> If the servlet is merely being reloaded then you should
start a
>separate thread that waits for all service methods to finish
executing and
>then destroys the servlet.
You don't need to worry about any of this!
The servlet's contract with the Servlet Engine *ensures* that the
servlet's destroy method() is called *only* when all service threads
within the servlet's service() method are complete.
You may consider that if you call destroy() on a particular servlet
then that servlet will be taken out of service before destroy() is
actually called.
If you call the servlet's own destroy() method from your service()
method that is a different matter... I don't think this is
supported... it's certainly won't have the desired effect because
destroy() does not actually remove the servlet from the engine, it is
a side effect of the removal.
This means that you don't have to worry about all the caching and
stuff that Ted specifies (although it does sound clever).
> 2. What sort of new security issues will servlets face when
accessing
> resources on the intranet
> for e.g. a file with access rights etc.??
>
The answer to this is it depends on the servlet-engine, some engines
have restrictive class loaders for every servlet, many just use the
JVM's normal class loader, some allow you to set up security for class
loaders.
If you want strict access you can get it, if you want lazy, easy
access - well, you can get that too.
Nic Ferrier
___________________________________________________________________________
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