File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!