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); }
...
相关推荐
sql server2008 cdc 数据实时同步到kafka,Debezium是捕获数据实时动态变化的开源的分布式同步平台。能实时捕获到数据源(Mysql、Mongo、PostgreSql)的:新增(inserts)、更新(updates)、删除(deletes)操作,实时...
我的小服务器 自己书写的servlet,仿照servlet源码 ex03 本章的应用程序所包含的...区别于与从java.net.ServerSocket类accept()方法接收一个替代,创建一个HttpProcessor实时并发生。该专有,调用其parse方法。 H
使用flink-connector-sqlserver-cdc 2.3.0把数据从SQL Server实时同步到MySQL中。
该工具在MongoDB与目标系统间同步数据,并跟踪MongoDB的oplog,保持操作与MongoDB的实时同步。用于连接MongoDB的插件,搭建的时候,遇到不少阻力,搭建时竟然保证版本的对应性。其次mongo connector的同步效率并不...
A HttpConnector implements a non-HTTP proxied connection through the CONNECT method.
presto.zip,presto-示例http connectorthe presto分布式大数据sql查询引擎的官方主页
flinkc-sql-connector-mysql,用于mysql数据实时同步
它又分为BIO Http Connector与NIO Http Connector两种,后者提供非阻塞IO与长连接Comet支持。 AJP Connector, 基于AJP协议,AJP是专门设计用来为tomcat与http服务器之间通信专门定制的协议,能提供较高的通信速度...
Zotero Connector
它又分为BIO Http Connector与NIO Http Connector两种,后者提供非阻塞IO与长连接Comet支持。 AJP Connector, 基于AJP协议,AJP是专门设计用来为tomcat与http服务器之间通信专门定制的协议,能提供较高的通信速度...
SAP.Connector.dll 与 SAP.Connector.Rfc.dll两个dll文件,欢迎下载
SAP .Net Connector 具体开发案例
eclipse的SVN插件,必须要装svn connector
firefox-connector
mysql connector 说明文档, 官方说明文档
mysql connector odbc 驱动
SAP Java Connector3.0
sap .net connector document
MySQL Connector C 6.1.rar c++与mysql相连