Parthiban Mahiby wrote:You are calling destroy() inside init but to use that, you are invoking servlet which is a REQUEST to a Web Container . so what happens is in order to respond to your request the servlet will be initalised(init) and service () method is invoked to do that.
No, this is at least misleading, if not downright wrong. No request needs to be made in order for the init method to be called. For example, the servlet may be listed as load-on-startup, in which case it will be initialized at web app startup time, not at request time. And even if it's not load-on-startup, the container may decide to init the servlet anyway (although that's not how the common containers work). Plus, the container is free to destroy and re-init servlets at any time it choose to do so (although, that, again, is not how common containers work).
The point is, the servlet spec says only that the servlet will be initialized before requests are sent to it, and that destroy() will be called after the last request has been handled - it does not say when, exactly, or how often, either of these events will occur.