Java CGI vs. Servlets

Jakub Mach picture Jakub Mach · Dec 6, 2011 · Viewed 22.2k times · Source

What are the main differences between CGI and Java servlets?

Answer

Victor Sorokin picture Victor Sorokin · Dec 6, 2011

Servlets are run in one process (HTTP server with additional features, which called Servlet Container) and they exist as long as that process exists.

CGI means every time there's client request, HTTP server creates new instance of process to serve this request. This is performance killer. Additionally, since there's new process per each request, it means CGI can't aggregate data from several requests in memory, as Servlets can, and must resort to external persistent storage (file or DB). This is performance killer as well.