着实就是首要挪用 protocolHandler.start()要领,继承跟踪,为了利便表述,我会把接下来的代码同一放在一路声名,代码如下:
- //1.类:AbstractProtocol implements ProtocolHandler,
- MBeanRegistration
- public void start() throws Exception {
- // 省略部门代码
- endpoint.start();
- }
- //2. 类:AbstractEndPoint
- public final void start() throws Exception {
- // 省略部门代码
- startInternal();
- }
- /**3.类:NioEndPoint extends AbstractJsseEndpoint<NioChannel,SocketChannel>
- * Start the NIO endpoint, creating acceptor, poller threads.
- */
- @Override
- public void startInternal() throws Exception {
- //省略部门代码
-
- // Start poller thread
- poller = new Poller();
- Thread pollerThread = new Thread(poller, getName() + "-ClientPoller");
- pollerThread.setPriority(threadPriority);
- pollerThread.setDaemon(true);
- pollerThread.start();
- startAcceptorThread();
- }
- }
到这里,其拭魅整个启动代码就完成了,我们看到最后是在NioEndPoint建设了一个Poller,而且启动它,这里必要增补声名下,这里只是以NioEndPoint为示列,着实Tomcat 首要提供了三种实现,别离是AprEndPoint,NioEndPoint,Nio2EndPoint,这里暗示了tomcat支持的I/O模子:
- APR:回收 Apache 可移植运行库实现,它按照差异操纵体系,别离用c重写了大部门IO和体系线程操纵模块,听说机能要比其他模式要好(未实测)。
- NIO:非阻塞 I/O
- NIO.2:异步 I/O
上述代码首要是开启两个线程,一个是Poller,一个是开启Acceptor,既然是线程,焦点的代码必定是run要领,我们来查察源码,代码如下:
- //4.类:Acceptor<U> implements Runnable
- public void run() {
- //省略了部门代码
- U socket = null;
- socket = endpoint.serverSocketAccept();
- // Configure the socket
- if (endpoint.isRunning() && !endpoint.isPaused()) {
- // setSocketOptions() will hand the socket off to
- // an appropriate processor if successful
- //焦点逻辑
- if (!endpoint.setSocketOptions(socket)) {
- endpoint.closeSocket(socket);
- }
- } else {
- endpoint.destroySocket(socket);
- }
-
- state = AcceptorState.ENDED;
- }
- //5.类:NioEndpoint
- protected boolean setSocketOptions(SocketChannel socket) {
- // Process the connection
- //省略部门代码
- try {
- // Disable blocking, polling will be used
- socket.configureBlocking(false);
- Socket sock = socket.socket();
- socketProperties.setProperties(sock);
- NioSocketWrapper socketWrapper = new NioSocketWrapper(channel, this);
- channel.setSocketWrapper(socketWrapper);
- socketWrapper.setReadTimeout(getConnectionTimeout());
- socketWrapper.setWriteTimeout(getConnectionTimeout());
- socketWrapper.setKeepAliveLeft(NioEndpoint.this.getMaxKeepAliveRequests());
- socketWrapper.setSecure(isSSLEnabled());
- //焦点逻辑
- poller.register(channel, socketWrapper);
- return true;
-
- }
(编辑:湖南网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|