Is the Servlet Init method called in a separate thread??

Is the Servlet Init method called in a separate thread??

Is the Servlet Init method called in a separate thread??
I know when the init is called
but when does the thread die(after running init ? or at the end ?)

The servlet specification doesn't say anything about that. Which means the answer to that question should be irrelevant to you as a writer of servlets. Why do you think you need to know?

I guess the real answer is, it doesn't matter. It's up to the people who implement the servlet container. Certainly it's called in a thread -- every bit of Java code anywhere must be called in a thread -- but I'm not sure what you meant by a "separate" thread. Anyway the servlet container writers might use a pool of threads, so that the threads don't ever die but are just recycled to handle more tasks. Or they might spawn threads which are used only once, in which case they would die after being used.

And you know that the init() method can either be called when the application starts or when the servlet handles its first request, right? Depending on how the servlet is configured. So the answer might be different for those two cases. Not that we need to know...

probably it is based on the implememtation of servlet container.....generally when the servlet object is created starting of init() method is done...**init() method is called when you send the request for first time**if you use LoadOnStartup in DeploymentDescriptor..and also when you modify the (.class) file...&also in least cases if no free memory is available in the server it remove servlet object and re create it...these all are the cases of when the servlet object is created then only init() method is called!

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright