Servlet Threading Model

Servlet Threading Model

The scalability issues of Java servlets are caused mainly by the server threading model:

Thread per connection

The traditional IO model of Java associated a thread with every TCP/IP connection. If you have a few very active threads, this model

can scale to a very high number of requests per second.

However, the traffic profile typical of many web applications is many persistent HTTP connections that are mostly idle while users read

pages or search for the next link to click. With such profiles, the thread-per-connection model can have problems scaling to the

thousands of threads required to support thousands of users on large scale deployments.

Thread per request

The Java NIO libraries support asynchronous IO, so that threads no longer need to be allocated to every connection. When the connection

is idle (between requests), then the connection is added to an NIO select set, which allows one thread to scan many connections for activity.

Only when IO is detected on a connection is a thread allocated to it. However, the servlet 2.5 API model still requires a thread to be

allocated for the duration of the request handling.

This thread-per-request model allows much greater scaling of connections (users) at the expense of a small reduction to maximum requests

per second due to extra scheduling latency.

Asynchronous Request handling

The Jetty Continuation (and the servlet 3.0 asynchronous) API introduce a change in the servlet API that allows a request to be dispatched

multiple times to a servlet. If the servlet does not have the resources required on a dispatch, then the request is suspended (or put into

asynchronous mode), so that the servlet may return from the dispatch without a response being sent. When the waited-for resources

become available, the request is re-dispatched to the servlet, with a new thread, and a response is generated.

时间: 2024-10-25 06:49:02

Servlet Threading Model的相关文章

Memcached source code analysis (threading model)--reference

Look under the start memcahced threading process memcached multi-threaded mainly by instantiating multiple libevent, are a main thread and n workers thread is the main thread or workers thread all through the the libevent management network event, in

threading模块

threading — Higher-level threading interface¶ Source code: Lib/threading.py This module constructs higher-level threading interfaces on top of the  lower level thread module. See also the mutex and Queue modules. The dummy_threading module is provide

Python多线程(threading)学习总结

注:此文除了例子和使用心得是自己写的,很多都是Python核心编程中的原文.原文文风应该能看出来,就不每个地方单独表明出处了. 线程(有时被称为轻量级进程)跟进程有些相似,不同的是,所有的线程运行在同一个进程中,共享相同的运行环境.它们可以想像成是在主进程或"主线程"中并行运行的"迷你进程". 线程有开始,顺序执行和结束三部分.它有一个自己的指令指针,记录自己运行到什么地方.线程的运行可能被抢占(中断),或暂时的被挂起(也叫睡眠),让其它的线程运行,这叫做让步.一个

<轻量级Java EE企业应用实战>1:JSP/Servlet及相关技术详解(二)

7 Servlet 介绍 7.1 Servlet 的开发 @WebServlet(name = "helloServlet", urlPatterns = {"/helloServlet"}) public class HelloServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws

【Hibernate学习笔记】第二章节:JSP/Servlet及相关技术详解

JSP(Java Servr Page)和Servlet是Java EE规范的两个基本成员,他们是Java Web开发的重点知识,也是Java EE开发的基础知识.JSP和Servlet的本质是一样的,因此JSP最终必须编译成Servlet才能运行,或者说JSP只是生成Servlet的"草稿"文件.JSP的特点是在HTML页面中嵌入了Java代码片段,从而可以动态的提供页面内容. 1.Web应用和web.xml文件 JSP.Servlet.Listener和Filter等都必须运行在W

Servlet 介绍

JSP 的本质就是 Servlet,开发者把编写好的 JSP 页面部署在 Web 容器中后,Web 容器会将 JSP 编译成对应的 Servlet. Servlet 的开发 Servlet 是个特殊的 Java 类,这个 Java 类必须继承 HttpServlet.每个 Servlet 可以响应客户端的请求.Servlet 提供不同的方法用于响应客户端请求. doGet:用于响应客户端的 GET 请求. doPost:用于响应客户端的 POST 请求. doPut:用于响应客户端的 PUT 请

python学习笔记——线程threading

1 线程threading 1.1 基本概述 也被称为轻量级的进程. 线程是计算机多任务编程的一种方式,可以使用计算机的多核资源. 线程死应用程序中工作的最小单元 1.2 线程特点 (1)进程的创建开销较大,线程创建开销较小 (2)一个进程中可以包含多个线程 (3)线程依附于进程的存在,多个线程共享进程的资源 (4)每个线程也拥有自己独特的特征,比如ID.指令集 注意: (1)进程有独立的空间,数据安全性较高 (2)线程使用进程的资源,即一般使用全局变量的方式进行线程间通信,所以需要较复杂的同步

Java Web基础 --- Servlet 综述(理论篇)

摘要: Web 技术成为当今主流的互联网 Web 应用技术之一,而 Servlet 是 Java Web 技术的核心基础.本文首先从请求/响应架构应用的大背景谈起 Servlet 的由来,明确 Servlet 的产生动机,并揭示了 Servlet 的本质以及其在标准MVC模式中所扮演的角色.紧接着,给出了 Servlet族的继承结构,并对族内的接口和抽象类作了进一步的介绍,并给出开发一个Servlet程序的常用做法.在此基础上,我们图文并茂地介绍了 Servlet 的生命周期与执行流程,清晰展现

Struts+Hibernate+Spring面试题合集及答案

Struts+Hibernate+Spring面试题合集及答案 Struts+Hibernate+Spring面试题合集 1 1. Hibernate部分 2 1.1. Hibernate工作原理 2 1.2. 什么是Hibernate的并发机制?怎么处理并发问题? 2 1.3. Hibernate自带的分页机制是什么?如果不使用Hibernate自带的分页,则采用什么方式分页? 3 1.4. hibernate的对象的三种持久化状态,并给出解释? 3 1.5. hibernate的三种状态之间