自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

開發(fā) 前端
connectionTimeout參數(shù)是說當客戶端有服務器連接以后,如果客戶端不輸入任何內容,那么超過了connectionTimeout設置的時間后連接會被斷開。

application.yml配置

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

測試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)程序能正常地響應。

結論:connectionTimeout參數(shù)與具體的請求響應時間是沒有關系的。

測試2:

通過HttpURLConnection發(fā)送請求

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("接收到內容:" + scan.next() + "\n耗時:" + (System.currentTimeMillis() - start)) ;
    }
    scan.close() ;
    con.disconnect() ;
    con = null ;
  }


}

結果:

圖片圖片


結論:connectionTimeout參數(shù)與什么樣的客戶端做連接請求沒關系。

測試3:

通過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 ) ;
  }


}

運行結果:

圖片圖片

差不多3s后程序結束了,也就是連接斷開了。接著測試:

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("準備發(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 ) ;
  }


}

結果1(什么也不做):

圖片圖片

結果2(控制臺不停的輸入內容):

圖片圖片


程序一開始運行,控制臺不停地輸入內容,發(fā)現(xiàn)程序一直正常,當停留3秒后在輸入內容,發(fā)現(xiàn)程序又斷開了。

結論:connectionTimeout參數(shù)是說當客戶端有服務器連接以后,如果客戶端不輸入任何內容,那么超過了connectionTimeout設置的時間后連接會被斷開。

完畢!?。?/p>

責任編輯:武曉燕 來源: Spring全家桶實戰(zhàn)案例源碼
相關推薦

2022-06-23 13:13:36

GitHub開發(fā)技巧

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è)信息化

2018-10-17 14:50:08

2010-08-23 09:56:09

Java性能監(jiān)控

2017-11-27 12:24:02

命令行代碼指令

2023-01-13 16:48:48

前端開發(fā)JavaScript

2021-07-22 09:28:35

DockerLinux命令

2015-06-11 16:48:46

2018-07-10 11:33:58

計算器iPhone刪除

2022-10-31 18:38:24

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

2022-06-19 14:38:55

Python

2017-10-22 15:34:34

手機內存清理內存手機

2021-11-02 19:14:58

Spring數(shù)據(jù)

2021-09-24 14:20:25

開發(fā)技能工具

2011-07-11 15:52:47

RCWindows

2021-01-15 05:39:13

HashMapHashTableTreeMap

2011-05-29 17:04:10

筆記本體驗
點贊
收藏

51CTO技術棧公眾號