AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當前位置:首頁 > 科技  > 軟件

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

來源: 責編: 時間:2023-10-13 14:37:55 219觀看
導讀application.yml配置server: port: 8081 tomcat: maxThreads: 10 maxConnections: 10 acceptCount: 1 connectionTimeout: 3000測試1:在controller中休眠10s>connectionTimeout@RestController@Reques

application.yml配置Joi28資訊網——每日最新資訊28at.com

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

測試1:

在controller中休眠10s>connectionTimeoutJoi28資訊網——每日最新資訊28at.com

@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" ;  }}

發現程序能正常地響應。Joi28資訊網——每日最新資訊28at.com

結論:connectionTimeout參數與具體的請求響應時間是沒有關系的。Joi28資訊網——每日最新資訊28at.com

測試2:

通過HttpURLConnection發送請求Joi28資訊網——每日最新資訊28at.com

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 ;  }}

結果:Joi28資訊網——每日最新資訊28at.com

圖片圖片Joi28資訊網——每日最新資訊28at.com


Joi28資訊網——每日最新資訊28at.com

結論:connectionTimeout參數與什么樣的客戶端做連接請求沒關系。Joi28資訊網——每日最新資訊28at.com

測試3:

通過Socket建立連接Joi28資訊網——每日最新資訊28at.com

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

運行結果:Joi28資訊網——每日最新資訊28at.com

圖片圖片Joi28資訊網——每日最新資訊28at.com

差不多3s后程序結束了,也就是連接斷開了。接著測試:Joi28資訊網——每日最新資訊28at.com

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("準備發送:" + 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(什么也不做):Joi28資訊網——每日最新資訊28at.com

圖片圖片Joi28資訊網——每日最新資訊28at.com

結果2(控制臺不停的輸入內容):Joi28資訊網——每日最新資訊28at.com

圖片圖片Joi28資訊網——每日最新資訊28at.com


Joi28資訊網——每日最新資訊28at.com

程序一開始運行,控制臺不停地輸入內容,發現程序一直正常,當停留3秒后在輸入內容,發現程序又斷開了。Joi28資訊網——每日最新資訊28at.com

結論:connectionTimeout參數是說當客戶端有服務器連接以后,如果客戶端不輸入任何內容,那么超過了connectionTimeout設置的時間后連接會被斷開。Joi28資訊網——每日最新資訊28at.com

完畢!!!Joi28資訊網——每日最新資訊28at.com

本文鏈接:http://www.tebozhan.com/showinfo-26-13585-0.html【震驚】Tomcat配置參數原來這么玩?99%的人不知道的秘密!

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: 兩個實驗讓我徹底弄懂了「訂閱關系一致」

下一篇: 聊聊 Reddit Programming 板塊的未來

標簽:
  • 熱門焦點
Top