[spring mvc]tomcat生成处理线程执行spring mvc时的思考
来源:互联网 发布:ally mac tyana种子 编辑:程序博客网 时间:2024/06/04 23:29
Each incoming request requires a thread for the duration of that request. If more simultaneous requests are received than can be handled by the currently available request processing threads, additional threads will be created up to the configured maximum (the value of the maxThreads
attribute). If still more simultaneous requests are received, they are stacked up inside the server socket created by the Connector, up to the configured maximum (the value of the acceptCount
attribute). Any further simultaneous requests will receive "connection refused" errors, until resources are available to process them.
spring mvc里面controller,service等bean默认是以单例模式运行。
对于一个浏览器请求,tomcat会指定(新建或者取空闲的)一个处理线程,在spring中不同的层面(MVC)都处于这个线程里面。
对于不同的请求,有可能是由同一个处理线程(tomcat处理线程池中)处理,但时间上不会有重叠。
所以在一个请求范围,使用ThreadLocal类也能够达到局部变量的效果。
模拟代码如下:
1.spring mvc controller
public class MockController {public void dosth() {Thread currThread = Thread.currentThread();String ci = ObjectUtil.obj2Str(currThread);// 显示当前线程(处理request的线程)System.out.println(ci);try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}
2.处理请求的线程
public class MockRequest extends Thread {private MockController con;public MockRequest(MockController con) {this.con = con;}public void run() {con.dosth();}}
3.服务器线程池
public class MockServerThreadPool {public static void main(String[] args) {// 模拟spring mvc controller,单例模式MockController con = new MockController();// 模拟服务器处理请求的线程池,最大线程数量为3ExecutorService es = Executors.newFixedThreadPool(3);for (int i = 0; i < 10; i++) {// 模拟请求es.execute(new MockRequest(con));}}}
- [spring mvc]tomcat生成处理线程执行spring mvc时的思考
- Spring MVC 线程安全问题的思考
- spring mvc tomcat 线程池的坑
- spring mvc 的执行顺序
- Spring MVC的执行流程
- spring mvc的执行流程
- spring的MVC执行原理
- spring mvc web应用启动时就执行特定处理(线程启动)
- spring mvc 的异常处理
- spring mvc的异常处理
- Spring-mvc 的处理流程
- spring mvc的异常处理
- spring mvc的处理流程
- Spring MVC 的 异常处理
- Spring Mvc数据的处理
- Spring MVC的异常处理
- 【spring-mvc】spring-mvc中handlerMethod的执行
- spring mvc web应用启动时执行特定处理
- Hibernate常用配置.
- 客户端TortoiseSVN的安装及使用方法
- CentOS操作MySQL问题集锦
- 招式学习之pathon(二)——字符串操作函数收集
- 利用PB技术实现输入框的水印效果
- [spring mvc]tomcat生成处理线程执行spring mvc时的思考
- Canny边缘检测算法原理及其VC实现详解(二)
- iOS简单排序--字母排序、NSDictionary排序
- poj 4052 Hrinity AC自动机
- 基于Linux下局域网内多Client向一个Service通信
- springmvc--注解crud
- shell中$0,$?,$!等的特殊用法
- ScrollView与ListView冲突解决
- MyBatis+Spring 事务管理