首页  

tomcat nio 读写关键代码     所属分类 tomcat 浏览量 163
org.apache.tomcat.util.net.NioEndpoint.NioSocketWrapper

public int read(boolean block, byte[] b, int off, int len)

org.apache.tomcat.util.net.SocketWrapperBase.write(boolean, byte[], int, int)
public final void write(boolean block, byte[] buf, int off, int len) 

org.apache.tomcat.util.net.NioEndpoint.NioSocketWrapper.doWriteInternal(boolean)
protected synchronized void doWriteInternal(boolean block) 



NioSocketWrapper
  private final NioSelectorPool pool;
  private Poller poller = null;
  private int interestOps = 0;
  private CountDownLatch readLatch = null;
  private CountDownLatch writeLatch = null;
  private final NioChannel socket;
  private final AbstractEndpoint< NioChannel> endpoint;
  private final Lock blockingStatusReadLock;
  private final WriteLock blockingStatusWriteLock;
  // The buffers used for communicating with the socket.
  protected volatile SocketBufferHandler socketBufferHandler = null;
  
public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) {
   super(channel, endpoint);
   pool = endpoint.getSelectorPool();
   socketBufferHandler = channel.getBufHandler();
}

java.nio.channels.ByteChannel

public class NioChannel implements ByteChannel
public NioChannel(SocketChannel channel, SocketBufferHandler bufHandler) {
  this.sc = channel;
  this.bufHandler = bufHandler;
}



CountDownLatch  readLatch  writeLatch 
当数据不可读,或者不可写时  阻塞 tomcat io 线程
数据不可读写,tomcat io 线程会在 readLatch  和 writeLatch 上等待


SocketBufferHandler
java.nio.ByteBuffer 
java NIO ByteBuffer 读写封装





Daemon Thread [http-nio-8086-exec-3] (Suspended (breakpoint at line 1182 in NioEndpoint$NioSocketWrapper))  
    owns: NioChannel  (id=51)   
    NioEndpoint$NioSocketWrapper.read(boolean, byte[], int, int) line: 1182 
    Http11InputBuffer.fill(boolean) line: 727   
    Http11InputBuffer.parseRequestLine(boolean) line: 401   
    Http11Processor.service(SocketWrapperBase<?>) line: 982 
    Http11Processor(AbstractProcessorLight).process(SocketWrapperBase<?>, SocketEvent) line: 66 
    AbstractProtocol$ConnectionHandler<S>.process(SocketWrapperBase<S>, SocketEvent) line: 760  
    NioEndpoint$SocketProcessor.run() line: 1480    
    ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1142  
    ThreadPoolExecutor$Worker.run() line: 617   
    TaskThread$WrappingRunnable.run() line: 61  
    TaskThread(Thread).run() line: 745  


Daemon Thread [http-nio-8086-exec-3] (Suspended (breakpoint at line 294 in SocketWrapperBase))  
    owns: NioChannel  (id=51)   
    NioEndpoint$NioSocketWrapper(SocketWrapperBase<E>).write(boolean, byte[], int, int) line: 294   
    Http11OutputBuffer.commit() line: 351   
    Http11Processor.action(ActionCode, Object) line: 646    
    Response.action(ActionCode, Object) line: 169   
    Response.sendHeaders() line: 354    
    OutputBuffer.doFlush(boolean) line: 319 
    OutputBuffer.close() line: 278  
    Response.finishResponse() line: 484 
    CoyoteAdapter.service(Request, Response) line: 364  
    Http11Processor.service(SocketWrapperBase<?>) line: 1096    
    Http11Processor(AbstractProcessorLight).process(SocketWrapperBase<?>, SocketEvent) line: 66 
    AbstractProtocol$ConnectionHandler<S>.process(SocketWrapperBase<S>, SocketEvent) line: 760  
    NioEndpoint$SocketProcessor.run() line: 1480    
    ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1142  
    ThreadPoolExecutor$Worker.run() line: 617   
    TaskThread$WrappingRunnable.run() line: 61  
    TaskThread(Thread).run() line: 745  


Daemon Thread [http-nio-8086-exec-3] (Suspended (breakpoint at line 1271 in NioEndpoint$NioSocketWrapper))  
    owns: NioEndpoint$NioSocketWrapper  (id=94) 
    owns: NioChannel  (id=93)   
    NioEndpoint$NioSocketWrapper.doWriteInternal(boolean) line: 1271    
    NioEndpoint$NioSocketWrapper(SocketWrapperBase<E>).doWrite(boolean) line: 472   
    NioEndpoint$NioSocketWrapper(SocketWrapperBase<E>).flushBlocking() line: 411    
    NioEndpoint$NioSocketWrapper(SocketWrapperBase<E>).flush(boolean) line: 401 
    Http11OutputBuffer.flushBuffer(boolean) line: 533   
    Http11OutputBuffer.endRequest() line: 318   
    Http11Processor.action(ActionCode, Object) line: 656    
    Response.action(ActionCode, Object) line: 167   
    OutputBuffer.close() line: 289  
    Response.finishResponse() line: 484 
    CoyoteAdapter.service(Request, Response) line: 364  
    Http11Processor.service(SocketWrapperBase<?>) line: 1096    
    Http11Processor(AbstractProcessorLight).process(SocketWrapperBase<?>, SocketEvent) line: 66 
    AbstractProtocol$ConnectionHandler<S>.process(SocketWrapperBase<S>, SocketEvent) line: 760  
    NioEndpoint$SocketProcessor.run() line: 1480    
    ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: 1142  
    ThreadPoolExecutor$Worker.run() line: 617   
    TaskThread$WrappingRunnable.run() line: 61  
    TaskThread(Thread).run() line: 745  



上一篇     下一篇
Tomcat NIO 处理机制

tomcat8的后台线程

tomcat请求处理过程

springboot2动态设置日志级别

postman上传文件

Map computeIfAbsent 实例