新聞中心
application.yml配置

瑪多網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)從2013年創(chuàng)立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選成都創(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)程序能正常地響應(yīng)。
結(jié)論:connectionTimeout參數(shù)與具體的請求響應(yīng)時間是沒有關(guān)系的。
測試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("接收到內(nèi)容:" + scan.next() + "\n耗時:" + (System.currentTimeMillis() - start)) ;
}
scan.close() ;
con.disconnect() ;
con = null ;
}
}結(jié)果:
圖片
結(jié)論:connectionTimeout參數(shù)與什么樣的客戶端做連接請求沒關(guān)系。
測試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 ) ;
}
}運行結(jié)果:
圖片
差不多3s后程序結(jié)束了,也就是連接斷開了。接著測試:
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 ) ;
}
}結(jié)果1(什么也不做):
圖片
結(jié)果2(控制臺不停的輸入內(nèi)容):
圖片
程序一開始運行,控制臺不停地輸入內(nèi)容,發(fā)現(xiàn)程序一直正常,當停留3秒后在輸入內(nèi)容,發(fā)現(xiàn)程序又斷開了。
結(jié)論:connectionTimeout參數(shù)是說當客戶端有服務(wù)器連接以后,如果客戶端不輸入任何內(nèi)容,那么超過了connectionTimeout設(shè)置的時間后連接會被斷開。
完畢!??!
當前題目:【震驚】Tomcat配置參數(shù)原來這么玩?99%的人不知道的秘密!
當前路徑:http://m.fisionsoft.com.cn/article/cdhgodh.html


咨詢
建站咨詢
