最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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寫入到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,不過springboot沒有提供對(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從List中刪除元素的幾種方式小結(jié)

    Java從List中刪除元素的幾種方式小結(jié)

    在Java中,List 接口提供了一個(gè) remove(Object o) 方法來移除列表中與給定對(duì)象相等的第一個(gè)元素,然而,直接使用這個(gè)方法來刪除列表中的元素有時(shí)并不是最優(yōu)的選擇,主要原因包括效率和同步性問題,本文介紹了Java從List中刪除元素的幾種方式,需要的朋友可以參考下
    2024-08-08
  • 解決Spring Boot 多模塊注入訪問不到j(luò)ar包中的Bean問題

    解決Spring Boot 多模塊注入訪問不到j(luò)ar包中的Bean問題

    這篇文章主要介紹了解決Spring Boot 多模塊注入訪問不到j(luò)ar包中的Bean問題。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Java使用jmeter進(jìn)行壓力測(cè)試

    Java使用jmeter進(jìn)行壓力測(cè)試

    本篇文章簡(jiǎn)單講一下使用jmeter進(jìn)行壓力測(cè)試。其壓測(cè)思想就是 通過創(chuàng)建指定數(shù)量的線程,同時(shí)請(qǐng)求指定接口,來模擬指定數(shù)量用戶同時(shí)進(jìn)行某個(gè)操作的場(chǎng)景,感興趣的小伙伴們可以參考一下
    2021-07-07
  • SpringBoot項(xiàng)目打包部署到Tomcat的操作流程

    SpringBoot項(xiàng)目打包部署到Tomcat的操作流程

    在最近一個(gè)項(xiàng)目中,維護(hù)行里一個(gè)年代較為久遠(yuǎn)的單體項(xiàng)目,需要將項(xiàng)目打包放到的tomcat服務(wù)器下運(yùn)行,所以本文就給大家介紹一下SpringBoot項(xiàng)目打包部署到Tomcat的流程步驟,需要的朋友可以參考下
    2023-08-08
  • JAVA實(shí)現(xiàn)往字符串中某位置加入一個(gè)字符串

    JAVA實(shí)現(xiàn)往字符串中某位置加入一個(gè)字符串

    這篇文章主要介紹了JAVA實(shí)現(xiàn)往字符串中某位置加入一個(gè)字符串,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • IDEA 顯示Run Dashboard窗口的2種方式(推薦)

    IDEA 顯示Run Dashboard窗口的2種方式(推薦)

    這篇文章主要介紹了IDEA 顯示Run Dashboard窗口的2種方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Java虛擬機(jī)運(yùn)行時(shí)棧的棧幀

    Java虛擬機(jī)運(yùn)行時(shí)棧的棧幀

    本節(jié)將會(huì)介紹一下Java虛擬機(jī)棧中的棧幀,會(huì)對(duì)棧幀的組成部分(局部變量表、操作數(shù)棧、動(dòng)態(tài)鏈接、方法出口)分別進(jìn)行介紹,最后還會(huì)通過javap命令反解析編譯后的.class文件,進(jìn)行分析方法執(zhí)行時(shí)的局部變量表、操作數(shù)棧等
    2021-09-09
  • 23種設(shè)計(jì)模式(18)java備忘錄模式

    23種設(shè)計(jì)模式(18)java備忘錄模式

    這篇文章主要為大家詳細(xì)介紹了23種設(shè)計(jì)模式之java備忘錄模式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • Visual?Studio?Code配置Tomcat運(yùn)行Java?Web項(xiàng)目詳細(xì)步驟

    Visual?Studio?Code配置Tomcat運(yùn)行Java?Web項(xiàng)目詳細(xì)步驟

    VS Code是一款非常棒的文本編輯器,具有配置簡(jiǎn)單、功能豐富、輕量簡(jiǎn)潔的特點(diǎn),并且極其適合處理中小規(guī)模的代碼,這篇文章主要給大家介紹了關(guān)于Visual?Studio?Code配置Tomcat運(yùn)行Java?Web項(xiàng)目的詳細(xì)步驟,需要的朋友可以參考下
    2023-11-11
  • SpringBoot自定義RestTemplate的攔截器鏈的實(shí)戰(zhàn)指南

    SpringBoot自定義RestTemplate的攔截器鏈的實(shí)戰(zhàn)指南

    在項(xiàng)目開發(fā)中,RestTemplate作為Spring提供的HTTP客戶端工具,經(jīng)常用于訪問內(nèi)部或三方服務(wù),但在實(shí)際項(xiàng)目中,我們往往需要對(duì)請(qǐng)求進(jìn)行統(tǒng)一處理,所以本文給大家介紹了SpringBoot自定義RestTemplate的攔截器鏈的實(shí)戰(zhàn)指南,需要的朋友可以參考下
    2025-07-07

最新評(píng)論

枣庄市| 安塞县| 长宁区| 阿图什市| 阿巴嘎旗| 河津市| 成安县| 侯马市| 西宁市| 洛浦县| 梧州市| 五原县| 嘉黎县| 义乌市| 油尖旺区| 关岭| 十堰市| 同江市| 桂林市| 东宁县| 乌兰县| 松滋市| 甘谷县| 郑州市| 抚远县| 巴东县| 纳雍县| 贡山| 福州市| 临桂县| 皮山县| 海门市| 从江县| 叙永县| 苗栗市| 陇川县| 轮台县| 南和县| 章丘市| 舞钢市| 哈密市|