日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
【震驚】Tomcat配置參數(shù)原來這么玩?99%的人不知道的秘密!

application.yml配置

瑪多網站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網頁設計、網站建設、微信開發(fā)、APP開發(fā)、成都響應式網站建設公司等網站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)從2013年創(chuàng)立到現(xiàn)在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選成都創(chuàng)新互聯(lián)

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>
標題名稱:【震驚】Tomcat配置參數(shù)原來這么玩?99%的人不知道的秘密!
當前地址:http://m.5511xx.com/article/cdhgodh.html