java 什么是“Sim阻塞”(在tomcat doc中可以看到)?

6ojccjat  于 2023-01-29  发布在  Java
关注(0)|答案(3)|浏览(109)

我在official tomcat configuration documentation中看到了以下描述(省略了APR连接器描述):

Java Blocking Connector       Java Nio Blocking Connector
Classname         Http11Protocol                  Http11NioProtocol   
Tomcat Version   3.x 4.x 5.x 6.x                       6.x            
Support Polling         NO                             YES            
Polling Size           N/A                   Unlimited - Restricted by mem
Read HTTP Request     Blocking                     Non Blocking
Read HTTP Body        Blocking                     Sim Blocking
Write HTTP Response   Blocking                     Sim Blocking
SSL Support           Java SSL                     Java SSL
SSL Handshake         Blocking                     Non blocking
Max Connections       maxThreads                   See polling size

“SIM卡屏蔽”是什么意思?

ejk8hzay

ejk8hzay1#

根据Filip Hanik(一个Tomcat提交程序),它意味着***"模拟阻塞"**(参考:Tomcat User Mailing list post)*

a6b3iqyw

a6b3iqyw2#

这只是一个猜测,但它可能代表模拟阻塞,意味着一个阻塞API包裹在底层的非阻塞nio api周围。

mlnl4t2r

mlnl4t2r3#

源代码:https://github.com/apache/tomcat/blob/8.5.x/java/org/apache/tomcat/util/net/NioEndpoint.java

/**
         * NioEndpoint.NioSocketWrapper.fillReadBuffer() 用于直接读取内容到 传入的任意 ByteBuffer 中
         *
         * @param block  是否阻塞读
         * @param buffer 待接收数据的buffer
         * @return 读取到的字节数
         * @throws IOException
         */
        private int fillReadBuffer(boolean block, ByteBuffer buffer) throws IOException {
            int n = 0;
            if (getSocket() == NioChannel.CLOSED_NIO_CHANNEL) {
                throw new ClosedChannelException();
            }
            if (block) { // if no readListener. block variable is true.
                long timeout = getReadTimeout();
                long startNanos = 0;
                do {
                    if (startNanos > 0) {
                        long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
                        if (elapsedMillis == 0) {
                            elapsedMillis = 1;
                        }
                        timeout -= elapsedMillis;
                        if (timeout <= 0) {
                            throw new SocketTimeoutException();
                        }
                    }
                    n = getSocket().read(buffer);
                    if (n == -1) {
                        throw new EOFException();
                    } else if (n == 0) {
                        if (!readBlocking) {
                            readBlocking = true;
                            registerReadInterest(); // <=============== (向关联的Poller)注册读事件.
                        }
                        synchronized (readLock) {
                            if (readBlocking) {
                                try {
                                    if (timeout > 0) {
                                        startNanos = System.nanoTime();
                                        readLock.wait(timeout); // block itself here < ===================
                                    } else {
                                        readLock.wait();
                                    }
                                } catch (InterruptedException e) {
                                    // Continue
                                }
                            }
                        }
                    }
                } while (n == 0); // TLS needs to loop as reading zero application bytes is possible
            } else {
                n = getSocket().read(buffer);
                if (n == -1) {
                    throw new EOFException();
                }
            }
            return n;
        }

相关问题