My understanding is that a CGI spawns a separate executable process on the server each time but that a Servlet does not do that – but I’m not sure how to describe what happens with a servlet by comparison. Since the servlet exists inside the JVM and the JVM is a single process, where does the Servlet exist in relation to it?
My understanding is that a CGI spawns a separate executable process on the server
Share
At runtime, a CGI process is launched by the web server as a separate OS shell. The shell includes an OS environment and process to execute the CGI code, which resides within the server’s file system. Each new http request launches a new OS shell on the server. The response time of CGI programs is high because CGI programs execute in their own OS shell, the creation of an OS shell is a heavy-weight activity for the OS.
In the case of a servlet, it runs as a thread in the web container instead of in a separate OS process. The web container itself is an OS process, but it runs as a service and is available continuously. When the number of requests for a servlet rises, no additional instances of the servlet are created. Each request is processed concurrently using one Java thread per request.
Note that a servlet executes as a thread within the web container’s process.