This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes init()  called at the same time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "init()  called at the same time" Watch "init()  called at the same time" New topic

init() called at the same time

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
If two threads try to acces the init method of a servlet then what will happen ?
If one thread is executing the statements in the init block of servlet, then at the same time if another request comes,then as the init is not been initialized what will happen to the request.Will the request die or wait till init is over and then call the service method.?
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
In my opinion, since a servlet instance is not available to handle requests until the servlet container calls the initialization method, I would think this possibly unique conflict would be handled by the servlet container.
my $0.02
Kevin Jones
Ranch Hand

Joined: Oct 29, 2003
Posts: 39
init will be called once and once only, So the issue of two requests entering the container concurrently, only the first request will cause the servlet to load and cause the init method to fire

Kevin Jones<br />Author: <a href="" target="_blank" rel="nofollow">Servlets and JSP: The J2EE Web Tier</a>
I agree. Here's the link:
subject: init() called at the same time
Similar Threads
when and how all methods of servlet are called
Calling init
init() called for only once for one servlet instance ?
simple quesition abt init() and constructor of a servlet.
If two clients call the same servlet...