欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

tomcat connection-timeout連接超時(shí)源碼解析

 更新時(shí)間:2023年11月24日 09:38:36   作者:codecraft  
這篇文章主要為大家介紹了tomcat connection-timeout連接超時(shí)源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

本文主要研究一下tomcat的connection-timeout

ServerProperties.Tomcat

org/springframework/boot/autoconfigure/web/ServerProperties.java

public static class Tomcat {
        /**
         * Access log configuration.
         */
        private final Accesslog accesslog = new Accesslog();
        /**
         * Thread related configuration.
         */
        private final Threads threads = new Threads();
        /**
         * Tomcat base directory. If not specified, a temporary directory is used.
         */
        private File basedir;
        /**
         * Delay between the invocation of backgroundProcess methods. If a duration suffix
         * is not specified, seconds will be used.
         */
        @DurationUnit(ChronoUnit.SECONDS)
        private Duration backgroundProcessorDelay = Duration.ofSeconds(10);
        /**
         * Maximum size of the form content in any HTTP post request.
         */
        private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
        /**
         * Maximum amount of request body to swallow.
         */
        private DataSize maxSwallowSize = DataSize.ofMegabytes(2);
        /**
         * Whether requests to the context root should be redirected by appending a / to
         * the path. When using SSL terminated at a proxy, this property should be set to
         * false.
         */
        private Boolean redirectContextRoot = true;
        /**
         * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect
         * will use relative or absolute redirects.
         */
        private boolean useRelativeRedirects;
        /**
         * Character encoding to use to decode the URI.
         */
        private Charset uriEncoding = StandardCharsets.UTF_8;
        /**
         * Maximum number of connections that the server accepts and processes at any
         * given time. Once the limit has been reached, the operating system may still
         * accept connections based on the "acceptCount" property.
         */
        private int maxConnections = 8192;
        /**
         * Maximum queue length for incoming connection requests when all possible request
         * processing threads are in use.
         */
        private int acceptCount = 100;
        /**
         * Maximum number of idle processors that will be retained in the cache and reused
         * with a subsequent request. When set to -1 the cache will be unlimited with a
         * theoretical maximum size equal to the maximum number of connections.
         */
        private int processorCache = 200;
        /**
         * Comma-separated list of additional patterns that match jars to ignore for TLD
         * scanning. The special '?' and '*' characters can be used in the pattern to
         * match one and only one character and zero or more characters respectively.
         */
        private List<String> additionalTldSkipPatterns = new ArrayList<>();
        /**
         * Comma-separated list of additional unencoded characters that should be allowed
         * in URI paths. Only "< > [ \ ] ^ ` { | }" are allowed.
         */
        private List<Character> relaxedPathChars = new ArrayList<>();
        /**
         * Comma-separated list of additional unencoded characters that should be allowed
         * in URI query strings. Only "< > [ \ ] ^ ` { | }" are allowed.
         */
        private List<Character> relaxedQueryChars = new ArrayList<>();
        /**
         * Amount of time the connector will wait, after accepting a connection, for the
         * request URI line to be presented.
         */
        private Duration connectionTimeout;
        /**
         * Static resource configuration.
         */
        private final Resource resource = new Resource();
        /**
         * Modeler MBean Registry configuration.
         */
        private final Mbeanregistry mbeanregistry = new Mbeanregistry();
        /**
         * Remote Ip Valve configuration.
         */
        private final Remoteip remoteip = new Remoteip();
        //......
    }
springboot的ServerProperties.Tomcat定義了connectionTimeout屬性,用于指定接受連接之后等待uri的時(shí)間

customizeConnectionTimeout

org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) {
        factory.addConnectorCustomizers((connector) -> {
            ProtocolHandler handler = connector.getProtocolHandler();
            if (handler instanceof AbstractProtocol) {
                AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
                protocol.setConnectionTimeout((int) connectionTimeout.toMillis());
            }
        });
    }
customizeConnectionTimeout將connectionTimeout寫(xiě)入到AbstractProtocol

AbstractProtocol

org/apache/coyote/AbstractProtocol.java

public void setConnectionTimeout(int timeout) {
        endpoint.setConnectionTimeout(timeout);
    }
AbstractProtocol將timeout設(shè)置到endpoint

AbstractEndpoint

org/apache/tomcat/util/net/AbstractEndpoint.java

public void setConnectionTimeout(int soTimeout) { 
        socketProperties.setSoTimeout(soTimeout); 
    }
    /**
     * Keepalive timeout, if not set the soTimeout is used.
     */
    private Integer keepAliveTimeout = null;
    public int getKeepAliveTimeout() {
        if (keepAliveTimeout == null) {
            return getConnectionTimeout();
        } else {
            return keepAliveTimeout.intValue();
        }
    }
AbstractEndpoint將timeout設(shè)置到socketProperties的soTimeout,另外它的getKeepAliveTimeout方法在keepAliveTimeout為null的時(shí)候,使用的是getConnectionTimeout

Http11Processor

org/apache/coyote/http11/Http11Processor.java

public SocketState service(SocketWrapperBase<?> socketWrapper)
        throws IOException {
        RequestInfo rp = request.getRequestProcessor();
        rp.setStage(org.apache.coyote.Constants.STAGE_PARSE);
        // Setting up the I/O
        setSocketWrapper(socketWrapper);
        // Flags
        keepAlive = true;
        openSocket = false;
        readComplete = true;
        boolean keptAlive = false;
        SendfileState sendfileState = SendfileState.DONE;
        while (!getErrorState().isError() && keepAlive && !isAsync() && upgradeToken == null &&
                sendfileState == SendfileState.DONE && !protocol.isPaused()) {
            // Parsing the request header
            try {
                if (!inputBuffer.parseRequestLine(keptAlive, protocol.getConnectionTimeout(),
                        protocol.getKeepAliveTimeout())) {
                    if (inputBuffer.getParsingRequestLinePhase() == -1) {
                        return SocketState.UPGRADING;
                    } else if (handleIncompleteRequestLineRead()) {
                        break;
                    }
                }
                //......
            }
            //......
        }
        //......
    }
Http11Processor的service方法在執(zhí)行inputBuffer.parseRequestLine時(shí)傳入了keptAlive、protocol.getConnectionTimeout()、protocol.getKeepAliveTimeout()參數(shù)

小結(jié)

springboot提供了tomcat的connection-timeout參數(shù)配置,其配置的是socket timeout,不過(guò)springboot沒(méi)有提供對(duì)keepAliveTimeout的配置,它默認(rèn)是null,讀取的是connection timeout的配置。

以上就是tomcat connection-timeout連接超時(shí)源碼解析的詳細(xì)內(nèi)容,更多關(guān)于tomcat connection-timeout連接超時(shí)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Java代碼讀取properties配置文件的示例代碼

    Java代碼讀取properties配置文件的示例代碼

    這篇文章主要介紹了Java代碼讀取properties配置文件,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • 淺談java線程狀態(tài)與線程安全解析

    淺談java線程狀態(tài)與線程安全解析

    本文主要介紹了淺談java線程狀態(tài)與線程安全解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • Java?Mybatis框架由淺入深全解析上篇

    Java?Mybatis框架由淺入深全解析上篇

    MyBatis是一個(gè)優(yōu)秀的持久層框架,它對(duì)jdbc的操作數(shù)據(jù)庫(kù)的過(guò)程進(jìn)行封裝,使開(kāi)發(fā)者只需要關(guān)注SQL本身,而不需要花費(fèi)精力去處理例如注冊(cè)驅(qū)動(dòng)、創(chuàng)建connection、創(chuàng)建statement、手動(dòng)設(shè)置參數(shù)、結(jié)果集檢索等jdbc繁雜的過(guò)程代碼本文將為大家初步的介紹一下MyBatis的使用
    2022-07-07
  • Quarkus集成apollo配置中心

    Quarkus集成apollo配置中心

    這篇文章主要介紹了Quarkus集成apollo配置中心,文中詳細(xì)的講解了Quarkus的config構(gòu)成,以及apollo集成實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助
    2022-02-02
  • Spring Boot攔截器和過(guò)濾器實(shí)例解析

    Spring Boot攔截器和過(guò)濾器實(shí)例解析

    這篇文章主要介紹了Spring Boot攔截器和過(guò)濾器實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • 簡(jiǎn)單易用的Spring?Boot郵件發(fā)送demo

    簡(jiǎn)單易用的Spring?Boot郵件發(fā)送demo

    本文將介紹如何使用Spring?Boot發(fā)送郵件,我們將演示如何配置SMTP郵件服務(wù)器,創(chuàng)建一個(gè)郵件模板,以及如何使用JavaMailSender發(fā)送郵件,我們還將介紹如何測(cè)試我們的郵件發(fā)送代碼
    2023-12-12
  • SpringBoot整合Swagger3的流程詳解

    SpringBoot整合Swagger3的流程詳解

    這篇文章主要介紹了SpringBoot整合Swagger3的流程詳解,Swagger最核心的類(lèi)就是Docket、它可以配置作者信息、掃描類(lèi)型,在SwaggerConfig配置類(lèi),添加@Configuration和@EnableOpenApi注解,需要的朋友可以參考下
    2024-01-01
  • JAVA中常見(jiàn)異常類(lèi)

    JAVA中常見(jiàn)異常類(lèi)

    本文主要介紹了JAVA中的常見(jiàn)異常類(lèi)。具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-01-01
  • Spring定時(shí)任務(wù)使用及如何使用郵件監(jiān)控服務(wù)器

    Spring定時(shí)任務(wù)使用及如何使用郵件監(jiān)控服務(wù)器

    這篇文章主要介紹了Spring定時(shí)任務(wù)使用及如何使用郵件監(jiān)控服務(wù)器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • SpringBoot程序的打包與運(yùn)行的實(shí)現(xiàn)

    SpringBoot程序的打包與運(yùn)行的實(shí)現(xiàn)

    本文主要介紹了SpringBoot程序的打包與運(yùn)行的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06

最新評(píng)論