When does the instance created by the server die? When does the instance created by the server die? multithreading multithreading

When does the instance created by the server die?


The servlet instance is created when your webapp starts, or when it is first required (if lazy-init is set). It is disposed of when your webapp stops, when it is GCed. In a normal production environment, I'd dare to state this never really happens (not counting deploying a new version).

Most (if not all) servlet containers work with a thread pool. This means they reuse threads to handle requests. So these threads never die; they return to the pool when they finish executing the request.

Of course, they do die when you shut down the server :)

From the standpoint from your application, you really should try to make your servlet stateless, and you can safely consider that each request is executed in its own dedicated thread.