How the create & maintain the servlet instance based on the request in servlet container?.In multi threaded model,each request created a new thread.So how the internally mapped with already created instance & request thread?.
Asked
Active
Viewed 475 times
-2
-
I would read through the servlet spec as defined by the JCP to understand this. It may differ from container to container. Just understand it is not the application developer's responsibility to instantiate servlets. – John Ament Jan 07 '12 at 13:06
-
I know Servlet instance creation is part of container.But my doubt is how to maintain & created instance in the servlet container. – suresh Jan 07 '12 at 13:29
-
Your question is terribly formulated (it's absolutely not *you* who have to create and manage servlets), but I think that you're basically asking the same as this user: http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading – BalusC Jan 07 '12 at 13:45
1 Answers
0
The lifetime of a servlet instance is not under your control. The container creates an instance of your class as it sees fit, calling you back via the lifecycle callbacks to tell you about it. Containers do not create a new thread every time; generally they have a pool of threads. The container will call the same servlet object in multiple threads if there are multiple concurrent requests. This is all documented in the specification. Exactly how this is organized is up to the implementation; if you are curious, download the source of (e.g.) Apache Tomcat and read it.

bmargulies
- 97,814
- 39
- 186
- 310