HttpConnector 与 HttpProcessor 同步控制
来源:互联网 发布:mac压缩pdf文件大小 编辑:程序博客网 时间:2024/06/06 05:00
HttpConnector 与 HttpProcessor 同步控制
Tomcat学习 HttpConnector和HttpProcessor启动流程和线程交互
一些疑问
1、对于assign方法里面的:
this.socket = socket;
和awai方法里面的:
Socket socket = this.socket;
难于理解。
就是:为什么 await 需要使用一个本地变量(socket)而不是返回实例的 socket 变量呢?
因为这样一来,在当前 socket 被完全处理之前,实例的 socket 变量可以赋给下一个前来的 socket 。
------------HttpProcessor---------------------------
private boolean available = false; public HttpProcessor(HttpConnector connector, int id) { super(); this.connector = connector; this.debug = connector.getDebug(); this.id = id; this.proxyName = connector.getProxyName(); this.proxyPort = connector.getProxyPort(); this.request = (HttpRequestImpl) connector.createRequest(); this.response = (HttpResponseImpl) connector.createResponse(); this.serverPort = connector.getPort(); this.threadName = "HttpProcessor[" + connector.getPort() + "][" + id + "]"; } private synchronized Socket await() { // Wait for the Connector to provide a new Socket while (!available) { try { wait(); } catch (InterruptedException e) { } } // Notify the Connector that we have received this Socket Socket socket = this.socket; available = false; notifyAll(); if ((debug >= 1) && (socket != null)) log(" The incoming request has been awaited"); return (socket); }-------------------public void run() { // Process requests until we receive a shutdown signal while (!stopped) { // Wait for the next socket to be assigned Socket socket = await(); if (socket == null) continue; // Process the request from this socket process(socket); // Finish up this request request.recycle(); response.recycle(); connector.recycle(this); } // Tell threadStop() we have shut ourselves down successfully synchronized (threadSync) { threadSync.notifyAll(); } }----------------synchronized void assign(Socket socket) { // Wait for the Processor to get the previous Socket while (available) { try { wait(); } catch (InterruptedException e) { } } // Store the newly available Socket and notify our thread this.socket = socket; available = true; notifyAll(); if ((debug >= 1) && (socket != null)) log(" An incoming request is being assigned"); }
-------------------HttpConnector-------------------
run(){// Loop until we receive a shutdown command while (!stopped) { // Accept the next incoming connection from the server socket Socket socket = null; try { socket = serverSocket.accept(); if (connectionTimeout > 0) socket.setSoTimeout(connectionTimeout); } catch (AccessControlException ace) { log("socket accept security exception: " + ace.getMessage()); continue; } catch (IOException e) { if (started && !stopped) log("accept: ", e); break; } // Hand this socket off to an appropriate processor HttpProcessor processor = createProcessor(); if (processor == null) { try { log(sm.getString("httpConnector.noProcessor")); socket.close(); } catch (IOException e) { ; } continue; } processor.assign(socket); // The processor will recycle itself when it finishes } // Notify the threadStop() method that we have shut ourselves down synchronized (threadSync) { threadSync.notifyAll(); }} ----------------- private HttpProcessor createProcessor() { synchronized (processors) { if (processors.size() > 0) return ((HttpProcessor) processors.pop()); if ((maxProcessors > 0) && (curProcessors < maxProcessors)) { return (newProcessor()); } else { if (maxProcessors < 0) { return (newProcessor()); } else { return (null); } } } }------------------------private HttpProcessor newProcessor() { HttpProcessor processor = new HttpProcessor(this, curProcessors++); if (processor instanceof Lifecycle) { try { ((Lifecycle) processor).start(); } catch (LifecycleException e) { log("newProcessor", e); return (null); } } created.addElement(processor); return (processor); }
...
0 0
- HttpConnector 与 HttpProcessor 同步控制
- Tomcat学习 HttpConnector和HttpProcessor启动流程和线程交互
- Tomcat源码解析(六):HttpConnector和HttpProcessor的异步工作机制
- 线程的控制与同步
- DWR的异步与同步的控制
- 知识库--HttpConnector Class
- 知识库--The HttpProcessor Class
- 多线程编程与同步控制(Java与C)
- 程序流程控制:同步与异步事件机制
- Eclipse版本控制工具subclipse与TortoiseSVN 同步管理项目
- java学习笔记之容器的同步与只读控制
- 容器的同步控制与只读设置JAVA133
- 2.学习操作系统之进程控制与同步
- 数据同步控制
- 控制java多线程同步
- 线程的同步控制
- 线程的同步控制
- 线程同步控制
- 《How Tomcat Works》读书笔记(一)
- 服务化介绍 和 快速入门
- 《How Tomcat Works》读书笔记(二):Connector
- 使用libjpeg进行编码之二:对I420YUV实现编码
- js 实现下载功能
- HttpConnector 与 HttpProcessor 同步控制
- 另一种fragment切换方式
- 使用megapixImage.js定位并展示上传的图片
- vc 自定义消息实现
- rsync linux 本地文件移动 断点续传
- Android 编程下模拟 HOME 键效果 ,返回键不退出APP,或者点击两次返回键退出APP
- 关于 HTTP GET/POST 请求参数长度最大值的一个理解误区
- 使用Socket编写Client-Server通信总结
- Google插件