Thanks for the quick answer! Can you shed more lights on how the servlet initiates itself upon a http request? From another http client, the servlet definitely 'new' itself, right? I thought the http request is a stateless protocol.
The fact that HTTP is stateless has nothing at all to do with the servlet life-cycle.
The container will load a servlet into memory before or on the first request to it. That single instance will be used to serve all requests to that servlet. This is why it is important to write servlets in a thread-safe manner. (Which yours is not, by the way.)
The servlet will be taken out of service by the container, usually when its context is being removed from service.
There are nuances to this, but that's the general life cycle of a servlet.
Joined: Oct 25, 2011
Thanks you so much. Yes, I just proved that another client will affect the variable 'counter' so it's not thread safe. I have to learn more on how to make it thread safe. Moving on now...