博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
how tomcat work
阅读量:6768 次
发布时间:2019-06-26

本文共 2359 字,大约阅读时间需要 7 分钟。

 笔记:

  1.等待接受连接:java.net.Socket socket =  java.net.ServerSocket.accept()

  2.处理连接:通过socket.getInputStream()把客户端HTTP传过来的信息封装成javax.servlet.http.HttpServletRequest对象

  3.Tomcat4 的默认连接器httpConnector

只负责获取socket,给processor线程异步处理,马上返回以便下一个前来的 HTTP 请求可以被处理

// 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;            }            //            if (debug >= 3)            //                log("run: Assigning socket to processor " + processor);            processor.assign(socket);

 

这里是 HttpProcessor 类的 assign 和 await 方法

  

/**

* Process an incoming TCP/IP connection on the specified socket. Any
* exception that occurs during processing must be logged and swallowed.
* <b>NOTE</b>: This method is called from our Connector's thread. We
* must assign it to our own thread so that multiple simultaneous
* requests can be handled.
*
* @param socket TCP socket to process
*/

  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");    }
/**     * Await a newly assigned Socket from our Connector, or null     * if we are supposed to shut down.     */    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);    }

 

 

转载于:https://www.cnblogs.com/shapeOfMyHeart/p/5746482.html

你可能感兴趣的文章
Razor Components启用服务器渲染 更提升低速网络浏览体验
查看>>
豆瓣的账号登录及api操作
查看>>
python 高阶函数:sorted(排序)
查看>>
前端与移动开发之vue-day1(3)
查看>>
网络osi七层复习,未复习整理完,后续补齐
查看>>
python--004--函数定义
查看>>
在中国,有多少程序员干到40了?那么其他人去干什么了?
查看>>
C盘里的文件夹都是干什么用的?
查看>>
PHP商城 Composer 以及PSR规范
查看>>
一个线程罢工的诡异事件
查看>>
嵌入式培训大纲 看看具体的课程学习内容有哪些
查看>>
华三模拟器telnet远程登陆
查看>>
带外监控
查看>>
淘宝美工技能分享!13个超级有用的PS技巧
查看>>
Oracle RAC 故障处理(二)(+DATA磁盘组故障)
查看>>
三大措施解决电厂安全管控难题
查看>>
oracle存储过程调试
查看>>
行级级触发器变通成语句级触发器-变通处理
查看>>
Oracle技术_Oracle口令文件
查看>>
网络RIP学习
查看>>