环境:springboot2.5.12
application.yml配置
复制server: port: 8081 tomcat: maxThreads: 10 maxConnections: 10 acceptCount: 1 connectionTimeout: 30001.2.3.4.5.6.7. 测试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" ; } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17. 发现程序能正常地响应。详解
结论:connectionTimeout参数与具体的配置请求响应时间是没有关系的源码库。
测试2 :
通过HttpURLConnection发送请求
复制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 ; } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18. 结果:
图片
结论:connectionTimeout参数与什么样的客户端做连接请求没关系。建站模板
测试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 ) ; } }1.2.3.4.5.6.7.8.9.10.11. 运行结果:
图片
差不多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("准备发送 :" + 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.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25. 结果1(什么也不做):
图片
结果2(控制台不停的输入内容):
图片
程序一开始运行,控制台不停地输入内容,香港云服务器参数发现程序一直正常
,意义当停留3秒后在输入内容,详解发现程序又断开了
。模板下载配置
结论:connectionTimeout参数是参数说当客户端与服务器连接以后 ,如果客户端不输入任何内容
,亿华云意义那么超过了connectionTimeout设置的详解时间后连接会被断开。
配置