Skip to content

Commit

Permalink
Site updated: 2024-03-21 18:50:19
Browse files Browse the repository at this point in the history
  • Loading branch information
吕成锋 committed Mar 21, 2024
1 parent 9d99169 commit 939645a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions posts/38923.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
s.parentNode.insertBefore(hm, s);
})();</script><script type="text/javascript" src="//lib.baomitu.com/clipboard.js/latest/clipboard.min.js"></script><script type="text/javascript" src="//lib.baomitu.com/toastr.js/latest/toastr.min.js"></script><link rel="stylesheet" href="//lib.baomitu.com/toastr.js/latest/toastr.min.css"><meta name="generator" content="Hexo 5.4.0"></head><body><div class="body_container"><div id="header"><div class="site-name"><h1 class="hidden">Tomcat-深入理解-核心组件Connector</h1><a id="logo" href="/.">frozeNwInd</a><p class="description">吕乘风的博客</p></div><div id="nav-menu"><a class="current" href="/."><i class="fa fa-home"> 首页</i></a><a href="/archives/"><i class="fa fa-archive"> 归档</i></a><a href="/tags/"><i class="fa fa-tag"> 标签</i></a><a href="/about/"><i class="fa fa-user"> 关于</i></a><a href="/history/"><i class="fa fa-history"> 历史</i></a><a href="/message/"><i class="fa fa-comment"> 留言</i></a></div></div><div class="pure-g" id="layout"><div class="pure-u-1 pure-u-md-3-4"><div class="content_container"><div class="post"><h1 class="post-title">Tomcat-深入理解-核心组件Connector</h1><div class="post-meta">2023-07-15<span> | </span><span class="category"><a href="/categories/technology/">technology</a><a href="/categories/technology/%E4%B8%AD%E9%97%B4%E4%BB%B6/">中间件</a><a href="/categories/technology/%E4%B8%AD%E9%97%B4%E4%BB%B6/Tomcat/">Tomcat</a></span></div><div class="post-content"><p>Connector(连接器)组件负责生成请求对象和响应对象的,Tomcat默认为HttpConnector,负责根据收到的Http请求报文生成Request对象和Response对象,并把这两个对象传递给Container,然后根据Response中的内容生成相应的HTTP报文。</p>
<p>Connector是使用<strong>ProtocolHandler</strong>来处理请求的,不同的ProtocolHandler代表不同的连接类型。<br>Http11Protocol使用的是普通Socket来连接的,<strong>Http11NioProtocol</strong>使用的是<strong>NioSocket</strong>来连接的。</p>
<p><img src="/posts/38923/tomcat-connector-%E4%BD%9C%E7%94%A8.png"></p>
<h2 id="ProtocolHandler"><a href="#ProtocolHandler" class="headerlink" title="ProtocolHandler"></a>ProtocolHandler</h2><p><img src="/posts/38923/tomcat-connector-ProtocolHandler.png"></p>
<ul>
<li><p>Endpoint<br> Endpoint用来处理底层Socket的网络连接,由于是处理底层的Socket网络连接,因此Endpoint是用来实现TCP/IP协议的。</p>
Expand Down
Binary file modified posts/38923/tomcat-connector-ProtocolHandler.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/38923/tomcat-connector-作用.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions posts/55324.html
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ <h3 id="从一个完整请求的角度看"><a href="#从一个完整请求的角
</ul>
<p>简而言之,Connector 连接器接收连接请求,创建Request和Response对象用于和请求端交换数据,然后分配线程让Engine(也就是Servlet容器)来处理这个请求,并把产生的Request和Response对象传给Engine。当Engine处理完请求后,通过Connector将响应返回给客户端。</p>
<h4 id="Tomcat如何接收到一个http请求"><a href="#Tomcat如何接收到一个http请求" class="headerlink" title="Tomcat如何接收到一个http请求"></a>Tomcat如何接收到一个http请求</h4><p><strong>Connector组件</strong><strong>Endpoint</strong>中的<strong>Acceptor</strong>监听客户端套接字连接并接收Socket。</p>
<h2 id="深入了解:Tomcat初始化与启动"><a href="#深入了解:Tomcat初始化与启动" class="headerlink" title="深入了解:Tomcat初始化与启动"></a>深入了解:Tomcat初始化与启动</h2><blockquote>
<h2 id="深入了解:Tomcat生命周期"><a href="#深入了解:Tomcat生命周期" class="headerlink" title="深入了解:Tomcat生命周期"></a>深入了解:Tomcat生命周期</h2><p>为了统一管理<code>Tomcat</code>中的核心组件的生命周期,专门设计了<code>LifeCycle</code>接口来统一管理。</p>
<h3 id="LifeCycle接口设计"><a href="#LifeCycle接口设计" class="headerlink" title="LifeCycle接口设计"></a>LifeCycle接口设计</h3><h2 id="深入了解:Tomcat初始化与启动"><a href="#深入了解:Tomcat初始化与启动" class="headerlink" title="深入了解:Tomcat初始化与启动"></a>深入了解:Tomcat初始化与启动</h2><blockquote>
<p>startup.bat -&gt; catalina.bat 中 找到启动的主类为 org.apache.catalina.startup.Bootstrap</p>
</blockquote>
<p><img src="/posts/55324/tomcat-%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E5%90%AF%E5%8A%A8-%E5%90%AF%E5%8A%A8%E6%B5%81%E7%A8%8B%E5%9B%BE.png"></p>
<h2 id="深入了解:核心组件Connector"><a href="#深入了解:核心组件Connector" class="headerlink" title="深入了解:核心组件Connector"></a>深入了解:核心组件Connector</h2><p>详情请见</p>
<h2 id="深入了解:核心组件Container"><a href="#深入了解:核心组件Container" class="headerlink" title="深入了解:核心组件Container"></a>深入了解:核心组件Container</h2><p>Container是容器的父接口,所有子容器都必须实现这个接口,简单来说就是服务器部署的项目是运行在Container中的。Container里面的Servlet获取到Connector传递过来对应的的Request对象和Response对象进行相应的操作。</p>
<h2 id="深入了解:核心组件Connector"><a href="#深入了解:核心组件Connector" class="headerlink" title="深入了解:核心组件Connector"></a>深入了解:核心组件Connector</h2><h2 id="深入了解:核心组件Container"><a href="#深入了解:核心组件Container" class="headerlink" title="深入了解:核心组件Container"></a>深入了解:核心组件Container</h2><p>Container是容器的父接口,所有子容器都必须实现这个接口,简单来说就是服务器部署的项目是运行在Container中的。<br>Container里面的Servlet获取到Connector传递过来对应的的Request对象和Response对象进行相应的操作。</p>
<h3 id="Mapper组件机制及请求处理机制"><a href="#Mapper组件机制及请求处理机制" class="headerlink" title="Mapper组件机制及请求处理机制"></a>Mapper组件机制及请求处理机制</h3><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/NaShiYu/article/details/111773908">https://blog.csdn.net/NaShiYu/article/details/111773908</a></p>
<h2 id="Tomcat-类加载机制"><a href="#Tomcat-类加载机制" class="headerlink" title="Tomcat 类加载机制"></a>Tomcat 类加载机制</h2><h3 id="打破双亲委派"><a href="#打破双亲委派" class="headerlink" title="打破双亲委派"></a>打破双亲委派</h3><p><strong>为什么Tomcat的类加载器不是双亲委派模型</strong><br>Java默认的类加载机制是通过双亲委派模型来实现的,而Tomcat实现的方式又和双亲委派模型有所区别。</p>
<p>原因在于一个Tomcat容器允许同时运行多个Web程序,每个Web程序依赖的类又必须是相互隔离的。<br>因此,如果Tomcat使用双亲委派模式来加载类的话,将导致Web程序依赖的类变为共享的。</p>
Expand All @@ -210,7 +210,7 @@ <h2 id="Tomcat-类加载机制"><a href="#Tomcat-类加载机制" class="headerl
distractionFreeMode: false
})
gitalk.render('container')
</script></div></div></div><div class="pure-u-1-4 hidden_mid_and_down"><div id="sidebar-toc"><div class="stoc-article" id="sidebar-stoc"><strong class="stoc-title"><i class="fa"> Contents </i></strong><div class="toc-nav" id="stoc"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Web%E5%AE%B9%E5%99%A8%E5%9F%BA%E7%A1%80%E8%AE%A4%E7%9F%A5"><span class="toc-text">Web容器基础认知</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C%E6%B5%8F%E8%A7%88%E5%99%A8%E7%9A%84%E4%BA%A4%E4%BA%92"><span class="toc-text">如何实现服务器和浏览器的交互</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFServlet"><span class="toc-text">什么是Servlet</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E5%92%8CSpring%E3%80%81Spring-MVC%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="toc-text">Tomcat和Spring、Spring MVC的关系</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Spring-MVC"><span class="toc-text">Spring MVC</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#DispatcherServlet"><span class="toc-text">DispatcherServlet</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-text">总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E6%BA%90%E7%A0%81%E7%BB%93%E6%9E%84"><span class="toc-text">Tomcat源码结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#javax"><span class="toc-text">javax</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#org-apache"><span class="toc-text">org.apache</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1"><span class="toc-text">Tomcat架构设计</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E7%BB%84%E4%BB%B6%E7%9A%84%E8%A7%92%E5%BA%A6%E7%9C%8B"><span class="toc-text">从组件的角度看</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#web-xml"><span class="toc-text">web.xml</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E4%B8%80%E4%B8%AA%E5%AE%8C%E6%95%B4%E8%AF%B7%E6%B1%82%E7%9A%84%E8%A7%92%E5%BA%A6%E7%9C%8B"><span class="toc-text">从一个完整请求的角度看</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Tomcat%E5%A6%82%E4%BD%95%E6%8E%A5%E6%94%B6%E5%88%B0%E4%B8%80%E4%B8%AAhttp%E8%AF%B7%E6%B1%82"><span class="toc-text">Tomcat如何接收到一个http请求</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9ATomcat%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E5%90%AF%E5%8A%A8"><span class="toc-text">深入了解:Tomcat初始化与启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9A%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6Connector"><span class="toc-text">深入了解:核心组件Connector</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9A%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6Container"><span class="toc-text">深入了解:核心组件Container</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Mapper%E7%BB%84%E4%BB%B6%E6%9C%BA%E5%88%B6%E5%8F%8A%E8%AF%B7%E6%B1%82%E5%A4%84%E7%90%86%E6%9C%BA%E5%88%B6"><span class="toc-text">Mapper组件机制及请求处理机制</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat-%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6"><span class="toc-text">Tomcat 类加载机制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%93%E7%A0%B4%E5%8F%8C%E4%BA%B2%E5%A7%94%E6%B4%BE"><span class="toc-text">打破双亲委派</span></a></li></ol></li></ol></div><script type="text/javascript" src="/js/toc.js?v=1.0.0"></script></div></div></div><div class="pure-u-1 pure-u-md-3-4"><div id="footer">Copyright © 2024 <a href="/." rel="nofollow">frozeNwInd.</a> Powered by<a rel="nofollow" target="_blank" href="https://hexo.io"> Hexo.</a><a rel="nofollow" target="_blank" href="https://github.com/tufu9441/maupassant-hexo"> Theme</a> by<a rel="nofollow" target="_blank" href="https://github.com/pagecho"> Cho.</a></div></div></div><a class="show" id="rocket" href="#top"></a><script type="text/javascript" src="/js/totop.js?v=1.0.0" async></script><script type="text/javascript" src="//lib.baomitu.com/fancybox/latest/jquery.fancybox.min.js"></script><script type="text/javascript" src="/js/fancybox.js?v=1.0.0"></script><link rel="stylesheet" type="text/css" href="//lib.baomitu.com/fancybox/latest/jquery.fancybox.min.css"><link rel="stylesheet" type="text/css" href="/css/search.css?v=1.0.0"><script type="text/javascript" src="/js/search.js?v=1.0.0"></script><script>var search_path = 'search.xml';
</script></div></div></div><div class="pure-u-1-4 hidden_mid_and_down"><div id="sidebar-toc"><div class="stoc-article" id="sidebar-stoc"><strong class="stoc-title"><i class="fa"> Contents </i></strong><div class="toc-nav" id="stoc"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Web%E5%AE%B9%E5%99%A8%E5%9F%BA%E7%A1%80%E8%AE%A4%E7%9F%A5"><span class="toc-text">Web容器基础认知</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%92%8C%E6%B5%8F%E8%A7%88%E5%99%A8%E7%9A%84%E4%BA%A4%E4%BA%92"><span class="toc-text">如何实现服务器和浏览器的交互</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFServlet"><span class="toc-text">什么是Servlet</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E5%92%8CSpring%E3%80%81Spring-MVC%E7%9A%84%E5%85%B3%E7%B3%BB"><span class="toc-text">Tomcat和Spring、Spring MVC的关系</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Spring-MVC"><span class="toc-text">Spring MVC</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#DispatcherServlet"><span class="toc-text">DispatcherServlet</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-text">总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E6%BA%90%E7%A0%81%E7%BB%93%E6%9E%84"><span class="toc-text">Tomcat源码结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#javax"><span class="toc-text">javax</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#org-apache"><span class="toc-text">org.apache</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1"><span class="toc-text">Tomcat架构设计</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E7%BB%84%E4%BB%B6%E7%9A%84%E8%A7%92%E5%BA%A6%E7%9C%8B"><span class="toc-text">从组件的角度看</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#web-xml"><span class="toc-text">web.xml</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E4%B8%80%E4%B8%AA%E5%AE%8C%E6%95%B4%E8%AF%B7%E6%B1%82%E7%9A%84%E8%A7%92%E5%BA%A6%E7%9C%8B"><span class="toc-text">从一个完整请求的角度看</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Tomcat%E5%A6%82%E4%BD%95%E6%8E%A5%E6%94%B6%E5%88%B0%E4%B8%80%E4%B8%AAhttp%E8%AF%B7%E6%B1%82"><span class="toc-text">Tomcat如何接收到一个http请求</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9ATomcat%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-text">深入了解:Tomcat生命周期</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#LifeCycle%E6%8E%A5%E5%8F%A3%E8%AE%BE%E8%AE%A1"><span class="toc-text">LifeCycle接口设计</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9ATomcat%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E5%90%AF%E5%8A%A8"><span class="toc-text">深入了解:Tomcat初始化与启动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9A%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6Connector"><span class="toc-text">深入了解:核心组件Connector</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%B1%E5%85%A5%E4%BA%86%E8%A7%A3%EF%BC%9A%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6Container"><span class="toc-text">深入了解:核心组件Container</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Mapper%E7%BB%84%E4%BB%B6%E6%9C%BA%E5%88%B6%E5%8F%8A%E8%AF%B7%E6%B1%82%E5%A4%84%E7%90%86%E6%9C%BA%E5%88%B6"><span class="toc-text">Mapper组件机制及请求处理机制</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Tomcat-%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6"><span class="toc-text">Tomcat 类加载机制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%93%E7%A0%B4%E5%8F%8C%E4%BA%B2%E5%A7%94%E6%B4%BE"><span class="toc-text">打破双亲委派</span></a></li></ol></li></ol></div><script type="text/javascript" src="/js/toc.js?v=1.0.0"></script></div></div></div><div class="pure-u-1 pure-u-md-3-4"><div id="footer">Copyright © 2024 <a href="/." rel="nofollow">frozeNwInd.</a> Powered by<a rel="nofollow" target="_blank" href="https://hexo.io"> Hexo.</a><a rel="nofollow" target="_blank" href="https://github.com/tufu9441/maupassant-hexo"> Theme</a> by<a rel="nofollow" target="_blank" href="https://github.com/pagecho"> Cho.</a></div></div></div><a class="show" id="rocket" href="#top"></a><script type="text/javascript" src="/js/totop.js?v=1.0.0" async></script><script type="text/javascript" src="//lib.baomitu.com/fancybox/latest/jquery.fancybox.min.js"></script><script type="text/javascript" src="/js/fancybox.js?v=1.0.0"></script><link rel="stylesheet" type="text/css" href="//lib.baomitu.com/fancybox/latest/jquery.fancybox.min.css"><link rel="stylesheet" type="text/css" href="/css/search.css?v=1.0.0"><script type="text/javascript" src="/js/search.js?v=1.0.0"></script><script>var search_path = 'search.xml';
if (search_path.length == 0) {
search_path = 'search.xml';
}
Expand Down
Loading

0 comments on commit 939645a

Please sign in to comment.