Java Servlet - Advantages Over CGI

Advantages Over CGI

The advantages of using Servlets are their fast performance and ease of use combined with more power over traditional CGI (Common Gateway Interface). Traditional CGI scripts written in Java have a number of disadvantages when it comes to performance:

  • When an HTTP request is made, a new process is created for each call of the CGI script. This overhead of process creation can be very system-intensive, especially when the script does relatively fast operations. Thus, process creation will take more time than CGI script execution. Java Servlets solve this, as a Servlet is not a separate process. Each request to be handled by a Servlet is handled by a separate Java thread within the web server process, omitting separate process forking by the HTTP daemon.
  • Simultaneous CGI request causes the CGI script to be copied and loaded into memory as many times as there are requests. However, with Servlets, there are the same amount of threads as requests, but there will only be one copy of the Servlet class created in memory that stays there also between requests.
  • Only a single instance answers all requests concurrently. This reduces memory usage and makes the management of persistent data easy.
  • A Servlet can be run by a Servlet container in a restrictive environment, called a sandbox. This is similar to an applet that runs in the sandbox of the web browser. This makes a restrictive use of potentially harmful Servlets possible.

Read more about this topic:  Java Servlet

Famous quotes containing the word advantages:

    For, the advantages which fashion values, are plants which thrive in very confined localities, in a few streets, namely. Out of this precinct, they go for nothing; are of no use in the farm, in the forest, in the market, in war, in the nuptial society, in the literary or scientific circle, at sea, in friendship, in the heaven of thought or virtue.
    Ralph Waldo Emerson (1803–1882)