偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

【震驚】Tomcat配置參數(shù)原來(lái)這么玩?99%的人不知道的秘密!

開(kāi)發(fā) 前端
connectionTimeout參數(shù)是說(shuō)當(dāng)客戶端有服務(wù)器連接以后,如果客戶端不輸入任何內(nèi)容,那么超過(guò)了connectionTimeout設(shè)置的時(shí)間后連接會(huì)被斷開(kāi)。

application.yml配置

server:
  port: 8081
  tomcat:
    maxThreads: 10
    maxConnections: 10
    acceptCount: 1  
    connectionTimeout: 3000

測(cè)試1:

在controller中休眠10s>connectionTimeout

@RestController
@RequestMapping("/test")
public class TestController {


  @GetMapping("/index")
  public Object index() {
    try {
      System.out.println(Thread.currentThread().getName()) ;
      TimeUnit.SECONDS.sleep(10) ;
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    return "success" ;
  }


}

發(fā)現(xiàn)程序能正常地響應(yīng)。

結(jié)論:connectionTimeout參數(shù)與具體的請(qǐng)求響應(yīng)時(shí)間是沒(méi)有關(guān)系的。

測(cè)試2:

通過(guò)HttpURLConnection發(fā)送請(qǐng)求

public class HttpURLConnectionDemo {


  public static void main(String[] args) throws Exception {
    HttpURLConnection con = (HttpURLConnection) new URL("http://localhost:8081/test/index").openConnection() ;
    con.setDoInput(true) ;
    con.setDoOutput(true) ;
    long start = System.currentTimeMillis() ;
    InputStream is = con.getInputStream() ;
    Scanner scan = new Scanner(is) ;
    while(scan.hasNext()) {
      System.out.println("接收到內(nèi)容:" + scan.next() + "\n耗時(shí):" + (System.currentTimeMillis() - start)) ;
    }
    scan.close() ;
    con.disconnect() ;
    con = null ;
  }


}

結(jié)果:

圖片圖片


結(jié)論:connectionTimeout參數(shù)與什么樣的客戶端做連接請(qǐng)求沒(méi)關(guān)系。

測(cè)試3:

通過(guò)Socket建立連接

public class TomcatConnectionTimeoutDemo {


  public static void main(String[] args) throws Exception {
    Socket socket = new Socket("127.0.0.1", 8081) ;
    long start = System.currentTimeMillis() ;
    InputStream is = socket.getInputStream() ;
    is.read() ;
    System.out.println(System.currentTimeMillis() - start ) ;
  }


}

運(yùn)行結(jié)果:

圖片圖片

差不多3s后程序結(jié)束了,也就是連接斷開(kāi)了。接著測(cè)試:

public class TomcatConnectionTimeoutDemo {


  public static void main(String[] args) throws Exception {
    Socket socket = new Socket("127.0.0.1", 8081) ;
    long start = System.currentTimeMillis() ;
    final OutputStream os = socket.getOutputStream() ;
    new Thread(() -> {
      Scanner scan = new Scanner(System.in) ;
      while(scan.hasNext()) {
        String content = scan.next() ;
        System.out.println("準(zhǔn)備發(fā)送:" + content) ;
        try {
          os.write(content.getBytes()) ;
          os.flush() ;
        } catch (IOException e) {
          e.printStackTrace() ;
        }
      }
    }).start() ;
    InputStream is = socket.getInputStream() ;
    is.read() ;
    System.out.println(System.currentTimeMillis() - start ) ;
  }


}

結(jié)果1(什么也不做):

圖片圖片

結(jié)果2(控制臺(tái)不停的輸入內(nèi)容):

圖片圖片


程序一開(kāi)始運(yùn)行,控制臺(tái)不停地輸入內(nèi)容,發(fā)現(xiàn)程序一直正常,當(dāng)停留3秒后在輸入內(nèi)容,發(fā)現(xiàn)程序又?jǐn)嚅_(kāi)了。

結(jié)論:connectionTimeout參數(shù)是說(shuō)當(dāng)客戶端有服務(wù)器連接以后,如果客戶端不輸入任何內(nèi)容,那么超過(guò)了connectionTimeout設(shè)置的時(shí)間后連接會(huì)被斷開(kāi)。

完畢?。?!

責(zé)任編輯:武曉燕 來(lái)源: Spring全家桶實(shí)戰(zhàn)案例源碼
相關(guān)推薦

2022-06-23 13:13:36

GitHub開(kāi)發(fā)技巧

2025-08-18 07:35:40

2021-01-12 12:33:20

Pandas技巧代碼

2025-04-16 07:06:43

2020-07-29 09:53:09

VSCode編碼工具插件

2020-11-12 10:16:32

企業(yè)信息化

2010-08-23 09:56:09

Java性能監(jiān)控

2018-10-17 14:50:08

2017-11-27 12:24:02

命令行代碼指令

2023-01-13 16:48:48

前端開(kāi)發(fā)JavaScript

2021-07-22 09:28:35

DockerLinux命令

2015-06-11 16:48:46

2018-07-10 11:33:58

計(jì)算器iPhone刪除

2022-10-31 18:38:24

MySQL數(shù)據(jù)訂單表

2022-06-19 14:38:55

Python

2017-10-22 15:34:34

手機(jī)內(nèi)存清理內(nèi)存手機(jī)

2021-11-02 19:14:58

Spring數(shù)據(jù)

2021-09-24 14:20:25

開(kāi)發(fā)技能工具

2011-07-11 15:52:47

RCWindows

2021-01-15 05:39:13

HashMapHashTableTreeMap
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)