知识库--HttpConnector Class
来源:互联网 发布:单片机主程序流程图 编辑:程序博客网 时间:2024/06/07 00:48
The HttpConnector Class
What the important is:
how HttpConnector creates a server socket;
how it maintains a pool of HttpProcessor;//降低响应成本消耗
how it serves HTTP requests;
Creating a Server Socket
The initialize method of HttpConnector calls the open private method that returns an instance of java.net.ServerSocket and assigns it to serverSocket. However, instead of calling the java.net.ServerSocket constructor, the open method obtains an instance of ServerSocket from a server socket factory.//Factory design
Maintaining HttpProcessor Instances
In 3.0 the HttpConnector instance had only one instance of HttpProcessor at a time, so it can only process one HTTP request at a time. In the default connector, the HttpConnector has a pool of HttpProcessor objects and each instance of HttpProcessor has a thread of its own. Therefore, the HttpConnector can serve multiple HTTP requests simultaneously.
The HttpConnector maintains a pool of HttpProcessor instances to avoid creating HttpProcessor objects all the time. The HttpProcessor instances are stored in a java.io.Stack called processors:
private Stack processors = new Stack();
In HttpConnector, the number of HttpProcessor instances created is determined by two variables: minProcessors and maxProcessors. By default, minProcessors is set to 5 and maxProcessors 20, but you can change their values through the set methods.
protected int minProcessors = 5; protected int maxProcessors = 20;
Initially, the HttpConnector object creates minProcessors instances of HttpProcessor. If there are more than the HttpProcessor instances can serve at a time, the HttpConnector creates more HttpProcessor instances until the number of instances reaches maxProcessors. After this point is reached and there are still not enough HttpProcessor instances, the incoming HTTP requests will be ignored. You can set maxProcessors to a negative number to kepp creating HttpProcessor instances. In addition, the curProcessors variable keeps the current number of Httpprocessor instances.
Here is the code that creates an initial number of HttpProcessor instances in the HttpConnector class’s start method:
while(curProcessors < minProcessors){ if((maxProcessors > 0 ) && (curProcessors >= maxProcessors)) break;//丢弃后面的连接 HttpProcessor processor = newProcessor(); recycle(processor); }
The newProcessor method constructs a new HttpProcessor object and increments curProcessors. The recycle method pushes the HttpProcessor back to the stack.
Each HttpProcessor instance is responsible for parsing the HTTP request line and headers and populates a request object. Therefore, each instance is associated with a request object and a response object. The HttpProcessor class’s constructor contains calls to the HttpProcessor class’s createRequest and createResponse methods.
- 知识库--HttpConnector Class
- 知识库--The HttpProcessor Class
- 知识库
- 知识库
- 知识库
- 知识库
- 知识库
- 知识库
- 知识库
- 知识库
- 知识库
- HttpConnector 与 HttpProcessor 同步控制
- Tomcat学习 HttpConnector和HttpProcessor启动流程和线程交互
- 进程知识库
- IT知识库
- IT知识库
- 进程知识库
- VC知识库
- Android设计模式之代理模式 Proxy
- 百度地图开发 (一)查看获取MD5和SHA1值 (调试)
- 搜索专题(BFS)HDU 1495-非常可乐
- 探讨PHP框架原理
- samba
- 知识库--HttpConnector Class
- eclipse切换工作空间保存当前工作空间相关配置
- JAVA中的多态
- android studio 加载外部文件出现红色J
- 正则表达式
- 1018 Public Bike Management --dijkstra+dfs
- squid部署
- git reset soft,hard,mixed之区别深解
- UBUNTU开机时出现“waiting for network configuration” 问题的解决 (转)