Here is the doubt I have come up with ServletContext is one per web-app and one per JVM. But if I am running more than one web-app on the same JVM. Then it has 2 ServletContext per JVM. Is it Possible? Can anybody elaborate on this?
Each webapp will have its own ServletContext. The way the api docs put it is:
There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.)
The "per web application" part means that if you set up the application in a cluster then each node in the cluster has a separate JVM, and that JVM will be running separate copies of all the applications, including a ServletContext for each webapp.
One per web application and one per JVM can be explained with the following tables.
Several Web Apps on one Server (one JVM):
Web App A - Server/JVM 1 - Context 1 Web App B - Server/JVM 1 - Context 2 Web App C - Server/JVM 1 - Context 3
Same Web App on several Servers (several JVMs):
Web App A - Server/JVM 1 - Context 1 Web App B - Server/JVM 1 - Context 2 Web App C - Server/JVM 1 - Context 3 Web App C - Server/JVM 2 - Context 4