Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet init() method  RSS feed

 
Dinesh Andavar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?)

 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dinesh Andavar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just curious to know what happens..
 
Paul Clapham
Sheriff
Posts: 22471
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
phanindra reddy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!