Hi,

init() is guarenteed to be called once *per instance*.  If two
requests arrive "simultaneously" then the first load of the
servlet should "lock out" the other until init() is finished
and the servlet is ready to serve requests.

But note that init() is NOT guarentted to be called only
once over the lifetime of the servlet engine. If the servlet
was unloaded (having "destroy()" called then) and then
re-loaded then init() shall be called again.  Same with
multiple instances - init() shall be called once for each
instance loaded.
(Such issues should be taken into consideration when
manipulating "global" data such as static class fields).

You can get definitive answers from the Servlet 2.2 Spec
(and from a brief review, it looks like the 2.3 Public Draft 1
may clarify a few points).

Cheers,

--Amos Shapira
WebCollage

> -----Original Message-----
> From: Rajni Singh [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, August 19, 2000 8:42 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Is it possible init() be called twice?
>
>
> init() is called only once, when the servlet is first
> loaded...
>
> rajni
>
> --- "S. Chen" <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Assume the servlet is loaded when it is first
> > called. In that case,
> > if two requests called the servlet at  exactly the
> > same time, is it
> > possible that the method init(...) be called twice?
> > So that one needs
> > do some synchronization inside init(...) is needed?
> >
> > Or, init(..) is guaranteed to be called only once?
> >
> > -SC.
> >
> >
> ______________________________________________________________
> _____________
> > 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
>
>
> __________________________________________________
> Do You Yahoo!?
> Send instant messages & get email alerts with Yahoo! Messenger.
> http://im.yahoo.com/
>
> ______________________________________________________________
> _____________
> 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

___________________________________________________________________________
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