CGI和Servlet如何执行不同? [英] How do CGIs and Servlets execute differently?

查看:84
本文介绍了CGI和Servlet如何执行不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是CGI每次都会在服务器上生成一个单独的可执行进程,但是Servlet不会这样做-但我不确定如何通过比较来描述Servlet会发生什么。由于Servlet存在于JVM内部,并且JVM是单个进程,因此Servlet与它有何关系?

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?

推荐答案

在运行时,Web服务器将CGI进程作为单独的OS Shell启动。该外壳程序包括一个OS环境和执行CGI代码的过程,该过程位于服务器的文件系统中。每个新的http请求都会在服务器上启动一个新的OS Shell。 CGI程序的响应时间很高,因为CGI程序在其自己的OS Shell中执行,而OS Shell的创建是OS的繁重活动。

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.

对于servlet,它作为线程在Web容器中运行,而不是在单独的OS进程中运行。 Web容器本身是一个OS进程,但它作为服务运行,并且可以连续使用。当对Servlet的请求数量增加时,不会创建该Servlet的其他实例。每个请求使用一个Java线程同时处理。

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.

请注意,servlet在Web容器的进程中作为线程执行。

Note that a servlet executes as a thread within the web container's process.

这篇关于CGI和Servlet如何执行不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆